944,156 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 2173
  • MySQL RSS
Oct 23rd, 2009
0

Inserting data to mysql database using php created form

Expand Post »
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.

MySQL Syntax (Toggle Plain Text)
  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());
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
futhonguy is offline Offline
69 posts
since Oct 2009
Oct 23rd, 2009
0
Re: Inserting data to mysql database using php created form
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.
Reputation Points: 395
Solved Threads: 192
Veteran Poster
darkagn is offline Offline
1,136 posts
since Aug 2007
Oct 23rd, 2009
0
Re: Inserting data to mysql database using php created form
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?
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
futhonguy is offline Offline
69 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: help - ordering
Next Thread in MySQL Forum Timeline: is mysql better than dbase 4





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC