Last incremented value

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
vipul73
Forum Commoner
Posts: 27
Joined: Mon May 12, 2003 5:32 am

Last incremented value

Post by vipul73 »

I am getting email address of a user from a feedback form and wish to generate a visitor number from that. I have tried inserting the email in a database and would like to get the last incremented value how do i get the same.

Code: Select all

<?php 
$email = $_POST["email"];
$db = mysql_connect("localhost", "root");
mysql_select_db("visitor",$db);
$sql = "INSERT INTO invoice (email) VALUES ('$email')";
$result = mysql_query($sql);
mysql_insert_id();
echo "Thank you! Information entered.\n";
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You've already got this:

Code: Select all

mysql_insert_id();
try setting it to a variable:

Code: Select all

$last_id = mysql_insert_id();
Mac
vipul73
Forum Commoner
Posts: 27
Joined: Mon May 12, 2003 5:32 am

Post by vipul73 »

:) Thanks it is working perfectly now
Post Reply