Jump to content

Recommended Posts

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

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.