RE: LAST_INSERT_ID?????

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Scott,

I typically use PHP's mysql_insert_id() function on a result. For example,
the following snippet from a function I use:

<snip>
	$result = mysql_query($sql) or
		die(mysql_error());
		
	if(!$result){
		$evNew = -1;//set evID to an impossible value in case the
query fails
	}else{
		$evNew = mysql_insert_id();//if the query succeeds, return
the id of the new event
	}

	return $evNew;
</snip>

Works like a charm.

Rich


> -----Original Message-----
> From: NIPP, SCOTT V (SBCSI) [mailto:sn4265@xxxxxxx]
> Sent: Thursday, July 15, 2004 4:17 PM
> To: php-db@xxxxxxxxxxxxx
> Subject:  LAST_INSERT_ID?????
> 
> 
> 	OK.  I know that a BUNCH of people have had this question, and I
> have read numerous Google threads on this, but nothing really seems to
> point out the resolution...  I have a table with the Primary Key as an
> auto_increment field.  Once I insert a new row of data into 
> the table I
> want to direct the user to a "Submitted" page.  I am trying 
> to pull the
> entry number to display for the user as a "ticket number".  I would
> assume that I should use the LAST_INSERT_ID function for this.
> Unfortunately, I am getting either failures or all zeroes for this
> output.
> 	I can't even get this function to work in a SQL query window.
> Please help!!!  I would attach code to this, but I am not sure what to
> attach.
> 
> Scott Nipp
> Phone:  (214) 858-1289
> E-mail:  sn4265@xxxxxxx
> Web:  http:\\ldsa.sbcld.sbc.com
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux