Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 12th, 2006, 01:01 PM
Authorized User
 
Join Date: Aug 2005
Location: , , Finland.
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
Reply With Quote
  #2 (permalink)  
Old October 19th, 2006, 12:01 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: colombo, WP, Sri Lanka.
Posts: 481
Thanks: 0
Thanked 3 Times in 3 Posts
Send a message via MSN to surendran Send a message via Yahoo to surendran
Default

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
Reply With Quote
  #3 (permalink)  
Old November 30th, 2006, 07:40 AM
Authorized User
 
Join Date: Nov 2006
Location: Bhopal, MP, India.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to talk2leo
Default

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.

Reply With Quote
  #4 (permalink)  
Old November 30th, 2006, 07:42 AM
Authorized User
 
Join Date: Nov 2006
Location: Bhopal, MP, India.
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to talk2leo
Default

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

Reply With Quote
  #5 (permalink)  
Old July 7th, 2007, 10:36 PM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Command to insert data in multiple tables? dstein4d Access VBA 3 November 18th, 2008 09:16 AM
how Insert record into two tables mfarooqw ASP.NET 1.0 and 1.1 Basics 2 July 10th, 2007 05:38 PM
insert data in two tables from form mfarooqw ASP.NET 1.0 and 1.1 Professional 1 July 10th, 2007 08:34 AM
Insert into Multiple Tables bmalex1 Beginning PHP 0 February 6th, 2006 12:45 PM
Insert into different Tables cs9896 SQL Language 2 September 16th, 2003 03:52 AM



All times are GMT -4. The time now is 09:45 PM.


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