mysql_insert_id()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

mysql_insert_id()

Post by gazzieh »

I am using the command mysql_insert_id() to load a page where a new article has been added to the system.

The problem is that when executed the result is 1 digit above the id value. So, if the unique value stored is 7 the code below gives 8.

Where am I going wrong?

Code: Select all

$insertQuery = "INSERT INTO cmsarticles (title,thearticle) VALUES ( '".$HTTP_POST_VARS['title']."', '".$HTTP_POST_VARS['thearticle']."')";
					
if ($result = $connector->query($insertQuery))
	{
	header("Location: ../article.php?id=".mysql_insert_id()."&act=v");
	}
else
	{
	echo('<center>Sorry, there was an error adding to the database</center>');
	}
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

Re: mysql_insert_id()

Post by gazzieh »

Ignore. All solved.

issue was not that section of code but with not ending a switch properly earlier.
Post Reply