Jump to content


Photo

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


  • Please log in to reply
4 replies to this topic

#1 ibdrumin81

ibdrumin81
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 31 August 2006 - 07:38 PM

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)

?>

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 31 August 2006 - 08:31 PM

http://ca3.php.net/m...l-insert-id.php
Legend has it that reading the manual never killed anyone.
My site

#3 ibdrumin81

ibdrumin81
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 31 August 2006 - 09:38 PM

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)

?>

#4 ibdrumin81

ibdrumin81
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 31 August 2006 - 10:05 PM

Correction,  I figured it out.  Thanks Again!

#5 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 31 August 2006 - 11:13 PM

I'm glad that you got there despite the cryptic nature of my reply  ;D
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users