Jump to content

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


ibdrumin81

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)

?>
Link to comment
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)

?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.