Dear all,

I am trying to submit my data on a php created form to mysql database where it is separate by 2 tables (device) and (location).

As some of the devices shared the same location, 2 tables are created as below.
For location table, i had created 2 fields: ID as (primary key) and area.
For device, i created 3 fields: ID (primary key), device_num and device_loc.

Using php, i created a form where user will enter the device number and the location.

The problem is i can insert the device number to my device table in mysql database and i have no idea how to link up the location table to my device table. Appreciated if some help of advise is given to me.

Below are the simple code of the insertion of my device table.

$val_d = $_POST['Device_num'];    //value submit from user 
$val_l = $_POST['location_area'];  //value submit from user 

$dev_insert = "INSERT INTO device (device_id, device_num)
	        VALUES (NULL, '$val_d')";
$results = mysql_query($dev_insert)
		or die (mysql_error());
7 Years
Discussion Span
Last Post by futhonguy

You need to do this in two separate SQL queries. First, use a select statement to retrieve the location ID given the posted area. Then use this result as the location number when inserting to the device table.


I forgot to mention that i have set a fix location areas in my database and therefore the form has a drop down option for the user to choose from.

Will this work the same way as well?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.