p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   PHP Databases (http://p2p.wrox.com/forumdisplay.php?f=97)
-   -   Insert Data into two tables (http://p2p.wrox.com/showthread.php?t=48942)

Lofa October 12th, 2006 01:01 PM

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.

surendran October 19th, 2006 12:01 AM

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

talk2leo November 30th, 2006 07:40 AM

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.


talk2leo November 30th, 2006 07:42 AM

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')";


ramirors July 7th, 2007 10:36 PM

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


All times are GMT -4. The time now is 09:10 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.