| | |
Inserting data to mysql database using php created form
Please support our MySQL advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2009
Posts: 20
Reputation:
Solved Threads: 0
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.
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)
$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());
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. ![]() |
Similar Threads
- How to Insert/Edit data from TAG SELECT HTML Form to MySQL Database? (PHP)
- updating data in mysql database using php forms (PHP)
- Help! my script couldn't submit form data to mysql database (PHP)
- Problem inserting data into Access database via php (PHP)
- How to import excel file data to mysql database (ASP.NET)
- retrieving a single cell of data from a MySQL database (PHP)
- Php code confusion. Not sure how to describe (PHP)
- dreamweaver, PHP and submit form query (PHP)
- Update entire Mysql DataBase with PhP (PHP)
Other Threads in the MySQL Forum
- Previous Thread: help - ordering
- Next Thread: is mysql better than dbase 4
| Thread Tools | Search this Thread |
6 action basic button c# c++ cgi check checkbox code coldfusion copy creat directrobot dom element email exists files form forms gdi+ html insert javascript login math multiple mysql open password php post robot select set struct table trouble upload validation validator vb vb6 video visual visualbasic visualbasic6 webbrowser website window wpf zend






