FutonGuy Posted October 27, 2009 Share Posted October 27, 2009 Dear all, I am new to PHP and MySql. I am trying to submit my data on a php created form to mysql database where it is separate by 2 tables (device) and (site). Below is a clearer pic using table to explain what i intend to do in order for you guys to assist me. Device Table ID Device_num Device_loc 1 AD192C 2 2 AD23O 3 3 FT432 3 4 GH324 1 Site Table ID area 1 Single 2 Dual 3 Quad 4 Octal I created a form where device_num is to be keyed in by user and a drop down option for Site table of 4 fields (see Site table above) to choose from. I managed to use the INSERT function to insert the device number into the database, however when i chose the area (say Dual), the Site_ID '2' will reflect '2' in the device table as well - cant seem to get that work out!. Below is my code i used : $val_d = $_POST['Device_num']; $val_s = $_POST['site_model']; $site_insert = "INSERT INTO site (site_id, site_model) VALUES (NULL, '$val_s')"; $results = mysql_query($site_insert) or die (mysql_error()); $siteid = "SELECT site_id FROM site WHERE site_id = device_site"; $siteid_id = mysql_query($siteid) or die (mysql_error()); $device_insert = "INSERT INTO device (device_id, device_num, device_site) VALUES (NULL, '$val_d', '$siteid_id')"; $results = mysql_query($device_insert) or die (mysql_error()); Thanks in advance for the help. Cheers Link to comment https://forums.phpfreaks.com/topic/179139-linking-2-tables-together-by-unique-referencing-numbers/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.