PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 23rd, 1999, 09:05 AM
fayadev
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Hi everybody,

Who can help me to fix a problem.

I want to join two tables.

TABLE_A
Aid int; //auto increment
name varchar;

TABLE_B
Bid int; //same id as Aid
Author varchar;

if ($voegtoe) { // name of button in form

//add a record ID Aid auto increment

$sql_A = "INSERT INTO TABLE_A (naam) VALUES
('$name')";
mysql_query($sql_A);

//Tryin' to get the last ID from TABLE_A
$result_A = mysql_query("SELECT Aid FROM TABLE_A");

$objectid= mysql_query($result_A);


//Tryin' to use Aid From TABLE_A

$sql_B = "INSERT INTO TABEL B (Bid, author) VALUES
('$objectid', '$author')";
mysql_query($sql_B);

}

TABLE_B is not getting the ID from TABLE_A, Why??

Regards,

Vin@ic

Reply With Quote
  #2  
Old August 23rd, 1999, 09:48 AM
rod k
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Because you are not getting the last id from table a. Your select will return the first id (actually it returns all but you're only getting the result for the first one.) There's a easier, safer way to do this. Check the php manual for the function mysql_insert_id(). This will do what you want.

Rod

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Insert into 2 tables??

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap