By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,810 Members | 818 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,810 IT Pros & Developers. It's quick & easy.

LAST_INSERT_ID() doesnt work properly

100+
P: 228
hi guys
i would appriciate your coments on this code - when i ran it for the very first time it doesnt see @last = LAST_INSERT_ID() but when i ran it next time it read it properly i need to know it imiedietely after i insert value into session1...

is there any other way to do it? insert into 2 tables at the same time ...?

[PHP]
if(!($sessid)){
session_register('sessid');
mysql_query("insert into session1 set
sessid=null,
ip='$ip',
ip2='$ip2',
cook=$cook,
time='$time',
user='$Guser',
pass='$pass',
ile='0'
");

//this doesnt work imiedietly last=0 - next time i run the script its ok ..
//it doesnt seem to see that i did inserted a values into session1.
$id5=mysql_query("SELECT @last := LAST_INSERT_ID()");
$sessid1=mysql_fetch_array($id5);
$sessid=$sessid1[0];

mysql_query("insert into session2 set
sessid=@last,
browser='$GLOBALS[HTTP_USER_AGENT]',
lang='$GLOBALS[HTTP_ACCEPT_LANGUAGE]',
host='$GLOBALS[HTTP_HOST]',
accept='$GLOBALS[HTTP_ACCEPT]',
referer='$GLOBALS[HTTP_REFERER]',

");
}[/PHP]


thanks a lot
jx2
Jun 6 '07 #1
Share this Question
Share on Google+
3 Replies


pbmods
Expert 5K+
P: 5,821
You'll probably like mysql_insert_id.
Jun 6 '07 #2

100+
P: 228
jx2
You'll probably like mysql_insert_id.

doesnt work :-( the same problem.
its doesnt see it imiedietly
it see it when i restart script :-(
Jun 6 '07 #3

100+
P: 228
jx2
ok its working (have to be in order :-)) thanks a lot!!
Jun 6 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.