Jump to content

Archived

This topic is now archived and is closed to further replies.

ibdrumin81

Retrieving last auto_increment id to use as a value in an email

Recommended Posts

I was wondering if anyone could enlighten me on how to retrieve the value of the last entry into the database.  Specifically I want to get the auto_increment id value, place it in a variable value ($ResNumber), then use that variable value for an immediately generated confirmation email. Thanks in advance.

My php file uses these components:

<?php

$con = mysql_connect("host","user","pw");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("db", $con);

(Other Misc Stuff that all works fine)

$confirmation = "Thank You, $HisName and $HerName for your request to attend the Party on $PartyDate.
Your Reservation Number is $ResNumber.  Please have this number available when arriving at the party.

Feel free to check our Guest List for other members attending the party on $PartyDate.

Can't wait to see you there!";


mail($to, $subject, $msg, "From: Form Submission\nReply-To: $EmailAddress\n");
mail($EmailAddress, $subject2, $confirmation, "From: Planet Pocono\nReply-To: $to\n");

mysql_query("INSERT INTO reservations (ReservationNumber, FirstParty, ProfileUsername, HisName, HerName, EmailAddress)
VALUES ('$ReservationNumber' , '$FirstParty' , '$ProfileUsername' , '$HisName' , '$HerName' , '$EmailAddress')");

mysql_close($con)

?>

Share this post


Link to post
Share on other sites
http://ca3.php.net/manual/en/function.mysql-insert-id.php

Share this post


Link to post
Share on other sites
Alright now I read that article, and I apoligize for being a newbie to the PHP/MySQL thing but I would think that I would make it like this to assign that value to a variable.  That is not working though.  Any suggestions?  Thanks!

$confirmation = "Thank You, $HisName and $HerName for your request to attend the Party on $PartyDate.
Your Reservation Number is $ResNumber.  Please have this number available when arriving at the party.

Feel free to check our Guest List for other members attending the party on $PartyDate.

Can't wait to see you there!";


mail($to, $subject, $msg, "From: Form Submission\nReply-To: $EmailAddress\n");
mail($EmailAddress, $subject2, $confirmation, "From: Planet Pocono\nReply-To: $to\n");

mysql_query("INSERT INTO reservations (ReservationNumber, FirstParty, ProfileUsername, HisName, HerName, EmailAddress)
VALUES ('$ReservationNumber' , '$FirstParty' , '$ProfileUsername' , '$HisName' , '$HerName' , '$EmailAddress')");


$ResNumber = mysql_insert_id();


mysql_close($con)

?>

Share this post


Link to post
Share on other sites
I'm glad that you got there despite the cryptic nature of my reply  ;D

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.