last_insert_id question

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

last_insert_id question

Post 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()");
?>
JPlush76
Forum Regular
Posts: 819
Joined: Thu Aug 01, 2002 5:42 pm
Location: Los Angeles, CA
Contact:

Post by JPlush76 »

nevermind, got it

Code: Select all

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