Inserting data to mysql database using php created form

Reply

Join Date: Oct 2009
Posts: 20
Reputation: futhonguy is an unknown quantity at this point 
Solved Threads: 0
futhonguy futhonguy is offline Offline
Newbie Poster

Inserting data to mysql database using php created form

 
0
  #1
Oct 23rd, 2009
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.

  1. $val_d = $_POST['Device_num']; //value submit FROM user
  2. $val_l = $_POST['location_area']; //value submit FROM user
  3.  
  4. $dev_insert = "INSERT INTO device (device_id, device_num)
  5. VALUES (NULL, '$val_d')";
  6. $results = mysql_query($dev_insert)
  7. OR die (mysql_error());
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 793
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 109
darkagn's Avatar
darkagn darkagn is offline Offline
Master Poster
 
0
  #2
Oct 23rd, 2009
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.
There are no stupid questions, only those too stupid to ask for help.
echo is a web developer's best friend.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 20
Reputation: futhonguy is an unknown quantity at this point 
Solved Threads: 0
futhonguy futhonguy is offline Offline
Newbie Poster
 
0
  #3
Oct 23rd, 2009
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?
Reply With Quote Quick reply to this message  
Reply

Tags
form, insert

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC