ibdrumin81 Posted August 31, 2006 Share Posted August 31, 2006 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)?> Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 31, 2006 Share Posted August 31, 2006 http://ca3.php.net/manual/en/function.mysql-insert-id.php Quote Link to comment Share on other sites More sharing options...
ibdrumin81 Posted August 31, 2006 Author Share Posted August 31, 2006 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)?> Quote Link to comment Share on other sites More sharing options...
ibdrumin81 Posted August 31, 2006 Author Share Posted August 31, 2006 Correction, I figured it out. Thanks Again! Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 31, 2006 Share Posted August 31, 2006 I'm glad that you got there despite the cryptic nature of my reply ;D Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.