 |
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|

October 12th, 2006, 01:01 PM
|
Authorized User
|
|
Join Date: Aug 2005
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Insert Data into two tables
I have two tables one for usernames and second for userdetails,
Users
_________________________
|ID (PK)| Usrname | PSW |
---------------------
|1 | User | P@sw|
-------------------------
Details
__________________________
|ID (FK)| firsn | Last_n |
--------------------------
| 1 | Test | Users |
--------------------------
Tables are related.
How can I with php insert data to both tables. So when new user registers and gives his username, password, first name and last name the data would insert into right tables.
|

October 19th, 2006, 12:01 AM
|
Friend of Wrox
|
|
Join Date: Oct 2003
Posts: 479
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
hello,
write both query,
$sql="insert into Users(ID,Usrname,PSW) values(1,'User','P@sw')";
$sql1="insert into Details(ID,firsn,Last_n) values(1,'Test','Users')";
surendran
(Anything is Possible)
http://ssuren.spaces.msn.com
|

November 30th, 2006, 07:40 AM
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi You can also do it like the query below..this will
remove the problem of id if it is AUTO_INCREMENT
$id = mysql_insert_id();
$sql="insert into Users(ID,Usrname,PSW) values('$id','User','P@sw')";
$sql1="insert into Details(ID,firsn,Last_n) values('$id','Test','Users')";
by doing so it will remobve the overhead of how to keep same id in both the tables..because if user is submitting information then you will not assign him/her id each time.
|

November 30th, 2006, 07:42 AM
|
Authorized User
|
|
Join Date: Nov 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
you can also remove quotation marks in the query as iid will be numeric
like this
$id = mysql_insert_id();
$sql="insert into Users(ID,Usrname,PSW) values($id,'User','P@sw')";
$sql1="insert into Details(ID,firsn,Last_n) values($id,'Test','Users')";
|

July 7th, 2007, 10:36 PM
|
Registered User
|
|
Join Date: Jul 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi, its posible to use:
$id = mysql_insert_id();
$sql="insert into Users(ID,Usrname,PSW) values($id,'User','P@sw')";
$sql1="insert into Details(ID,firsn,Last_n) values($id,'Test','Users')";
in one single
$sql
Thanks...
RRS
|
|
 |