Storing variables in variables(PHP related) - 03/29/05 11:45 PM
Okay check it out. I am stuck and ready to pop. Here is what I am doing.
I created a database in mySQL for all types of elements. Then a database for all data to go with these elements. And finaly a database to store user feedback. 3 databases.
Now... This puts all data into an array in the final while statement. If the SQL is dorked up forget about it. The sql in my script is fine and this is not an exact copy. I put this here so you get a general idea. Here is the bulk of my issue.
$var_for_next_query3 now holds 92 values. That is to say it is an array with 92 values to it. I want to just slap all values into a sql insert statement but can seem to do it. Instead it give me the variable names.
Here is what I get.
http://www.tradebikes.com/forms/bike_forms/input.php?biketype=3
If you submit you should see something like this
This is exactly how it inserts into the database. with the '$saddle_model'. So for the $1,000,000 question. How can I get all the variables to dissplay thier values encased in 1 variable?
See all form elements on
http://www.tradebikes.com/forms/bike_forms/input.php?biketype=3
are dynamically made using PHP and MySQL. So...
same with select tags(drop down menus).
So on the submit page I thought I might beable to just hit the database and get the variable names, slap a "$" in front of them. But for some reason it is not working... Here is my actual code minus login info
Any help and I will love you forever.
I created a database in mySQL for all types of elements. Then a database for all data to go with these elements. And finaly a database to store user feedback. 3 databases.
Code
$query1 = mysql_query(SELECT * FROM ELEMENTS TABLE Where this = '$that'); While($query12 = mysql_fetch_array($query1)){ $var_for_next_query = $query12[colum_name]; } $query2 = mysql_query(SELECT * FROM DATA_TABLE Where this = '$var_for_next_query'); While($query22 = mysql_fetch_array($query2)){ $var_for_next_query2 = "'".$query22[colum_name].",'"; $query3 = mysql_query(SELECT * FROM $var_for_next_query2 Where this = 'true'); While($query32 = mysql_fetch_array($query3)){ $var_for_next_query3 .= "'".$query32[colum_name]."',"; }
$var_for_next_query3 now holds 92 values. That is to say it is an array with 92 values to it. I want to just slap all values into a sql insert statement but can seem to do it. Instead it give me the variable names.
Code
$dg = mysql_query(insert into Table set($var_for_next_query2)VALUES($var_for_next_query3));
http:/
If you submit you should see something like this
Code
$dg = mysql_query("INSERT INTO Bikes(Manufa_brand, fram_size, frame_mat, frame_brk_boss, frame_dropout_type, frame_headtube_diameter, frame_mod, fork_brand, fork_siz, fork_material, fork_travel, fork_head_dia, frk_brk_boss_typ, fork_dropout_typ, fork_mod, headset_brand, head_tub_diam, headset_mod, shift_mod, sifter_brd, drivetrain, brk_sys_mod, brk_sys_man, Brake_lever_brd, Brake_lever_mod, brake_calpr_brnd, brake_cal_mod, brake_Disk_size, brake_disk_model, brake_disk_manufac, brake_sys_cnfg, stem_mod, stem_brd, stem_mat, handle_mod, handle_bar_brnd, handle_mat, handlebar_type, f_derail_mod, f_derail_brd, f_drail_typ, f_derail_materi, r_derail_mod, r_derail_brd, r_derail_typ, r_derail_materi, casset_mod, casset, cassette_typ, cassette_materi, pdl_mod, pdl_brd, pdl_typ, pdl_materi, bottom_mod, bottom_brd, bottom_typ, botom_material, crank_mod, crank_brd, crank_siz, crank_typ, chainten_mod, chainten_man, chainten_siz, wheelset_model, wheel_brand_name, wheel_config, rim_hole_count, hub_model, hub_brand, hub_typ, rim_model, rim_brand, rear_wheel_mod, rear_wheel_manu, rear_wheel_cnfg, rear_wheel_hol_cnt, rear_hub_mod, rear_hub_manu, rear_hub_typ, rear_rim_mod, rear_rim_manu, axle_model, axle_brand, axle_size, grip_model, grip_manu, grip_typ, sadle_mod, sadle, seat_post, Valid_use, time_made, ip_addy, type) VALUES('$manufac', '$siz', '$frame_mat', '$fram_brk_boss', '$fram_dropout_type', '$headtub_diam', '$fram_model', '$fork_manufac', '$fork_size', '$fork_materi', '$fork_trav', '$frk_head_dia', '$frk_brk_boss', '$drop_typ', '$fork_model', '$head_man', '$head_tube_diam', '$headset_model', '$shift_model', '$shift_manufact', '$drivetrain_shift', '$brake_sys_model', '$brake_sys_manufac', '$brake_lever_manufac', '$brake_lever_model', '$brake_calip_manufac', '$brake_calip_model', '$brake_disk_size', '$brake_disk_model', '$brake_disk_manufac', '$brake_sys_cnfg', '$stem_model', '$stem_manufac', '$stem_mater', '$handlebar_model', '$handlebar_model', '$handlebar_mater', '$handlebar_type', '$front_derail_model', '$front_derail_manufac', '$front_derail_type', '$front_derail_mater', '$rear_derail_model', '$rear_derail_manufac', '$rear_derail_type', '$rear_derail_mater', '$cassette_model', '$cassette_manufac', '$cassette_type', '$cassette_mater', '$pedal_model', '$mtn_pedals', '$pedal_type', '$pedal_material', '$bbracket_model', '$bbrack_manufac', '$bbracket_typ', '$bb_material', '$crankset_model', '$crankset_manufac', '$crankset_size', '$crankset_type', '$chainten_model', '$chainten_manufac', '$chainten_size', '$front_wheelset_model', '$front_wheelset_manufac', '$front_wheelset_config', '$frt_wheelset_hole_cnt', '$frnt_hub_model', '$front_hub_manufac', '$frnt_hub_type', '$frnt_rim_model', '$frnt_rim_manufac', '$rear_wheelset_model', '$rear_wheelset_manufac', '$rear_wheelset_config', '$rear_wheelset_hole_cnt', '$rear_hub_model', '$rear_hub_manufac', '$rear_hub_type', '$rear_rim_model', '$rear_rim_manufac', '$axle_model', '$axel_manufac', '$axle_sixe', '$grip_model', '$grip_manufac', '$grip_type', '$saddle_model', '$saddle_manufac', '$saddle_materi', '59','1112110178','159.67.20.48', '3')")
See all form elements on
http:/
are dynamically made using PHP and MySQL. So...
Code
<input type="from database" name="from database">
So on the submit page I thought I might beable to just hit the database and get the variable names, slap a "$" in front of them. But for some reason it is not working... Here is my actual code minus login info
Code
}else if($cmd == "submit"){ $my_count = 0; $password = "psswd"; $username = "login"; $db = "db_name"; $dbh=mysql_connect ("localhost", $username, $password); mysql_select_db($db); $dg = mysql_query("SELECT * from table WHERE id = '$biketype'"); While($dg2 = mysql_fetch_array($dg)){ $bike_name_short = $dg2['name']; } $set_up = mysql_query("SELECT * FROM table2 WHERE $bike_name_short = 'true' order by id"); While($set_up2 = mysql_fetch_array($set_up)){ $part_group = $set_up2['name']; $section_title = $set_up2['user_view']; $part_list = mysql_query ("SELECT * FROM $part_group WHERE $bike_name_short = 'true'"); While($part_list2 = mysql_fetch_array($part_list)){ $first_variable_name = "\$".$part_list2['form_name'].""; $ad_db_field .= "".$part_list2['the_ads_table'].", \n"; $variable_name .= "'$first_variable_name', \n"; } } $test_var = "$variable_name"; echo " <hr>$test_var<hr> "; $date_epoch = date("U"); echo "<hr color=\"red\"><hr color=\"red\">\$dg = mysql_query(\"INSERT INTO Table3($ad_db_field Valid_use, time_made, ip_addy, type) VALUES ($variable_name '$my_sess[5]','$date_epoch','$REMOTE_ADDR', '$biketype')\")<hr color=\"red\"><hr color=\"red\">"; mysql_close(); $password = "psswd"; $username = "login"; $db = "wethe_ads"; $dbh=mysql_connect ("localhost", $username, $password); mysql_select_db($db); $dg = mysql_query("INSERT INTO table3($ad_db_field Valid_use, time_made, ip_addy, type) VALUES($variable_name '$my_sess[5]','$date_epoch','$REMOTE_ADDR', '$biketype')"); if($dg){ echo "good"; }else{ echo "fail"; echo " ".mysql_error(); } }