Page 1 of 1

last_insert_id question

Posted: Fri Sep 20, 2002 11:42 am
by JPlush76
basically what I'm trying to do is enter a customer into the database then register their user_id (which is the autoincrement id) as a session variable.

I've read through the mysql manual but they don't have much info on last_insert_id

anyone know what I'm doing wrong? when I echo the session variable its always 0

Code: Select all

<?php
// ENTER USER IN DATABASE
	
 		$result = query_db("INSERT INTO customers (cust_first,cust_last,cust_email) "
		."VALUES  ('".$_POSTї'f_first']."', '".$_POSTї'f_last']."','".$_POSTї'f_email']."')");
		
// REGISTER SESSION VARIABLES

$_SESSIONї'user_id'] = query_db("SELECT last_insert_id()");
?>

Posted: Fri Sep 20, 2002 11:58 am
by JPlush76
nevermind, got it

Code: Select all

<?php
$_SESSIONї'user_id'] = mysql_insert_id();
?>