I send an email from a submit form used to insert data into a database base with a copy of the data in the form to the instigator email address. I want to include in that email the auto increment ID for that record row in the database table.
I anticipated that the solution would have to follow that sequence but what I’m really asking is "How"t o do you do it - code wise. I am not a professional coder just a hobbyist and could not fathom the structure of the necessary code
Most of the php database extensions have a function/method to get the last insert id, following the successful execution of an INSERT query. Getting this value just takes researching what the one line function/method call is for the database extension you are using.
Thanks mabismad for the assistance. However I have already tried that approach and is the reason why I posted here because I cannot find the code that can simultaneously post the form data to the database, collect the generated ‘id’ once tht data is inserted, bring it back to the php file and inserted into the that file in order to include it in the email for dispatch at the time upload php code is initiated
I was just looking to see if anyone had a solution to this quandary
^ Agreed - we need to see the code you’re struggling with. While I don’t send emails containing the last insert ID, I do retrieve it and use it. Which specific part are you having trouble with - retrieving the last insert ID, or putting it into an email message?
$sender = " email@form-entered by submitters ";
$backup = "firstname.lastname@example.org";
$subject = "New Notice Posted on - Our Place Website";
// all the following ‘$variable’ are collected from the form
$message = "Hi $fname \n
You posted the following Notice on the Community Notice Board:\n $comment \n".
"With Mobile Phone contact: $mobile\n".
"The Notice will stay posted for 30 days - unless you reply sooner, by email, that the Notice is no longer required\n".
"After 30 days you will receive an email. You may extend for another 30 days by reply. \n".
"Good Luck with your Notice\n".
"Warren\n " ;
$to = "$email";
$headers = "From: $sender \r\n";
$headers .= "Cc to: $email \r\n";
$headers .= "Bc to: $backup \r\n";
As i explained, as the database is getting bigger it is harder to visually locate the post within the DB TABLE for which a user has advised is no longer needed and wants taken down so IF i can include the “id” in the original advise email i can us it to quickly find it straight away
You may be using MySQL as the database engine, but the library of functions that you use to connect to it will be either mysqli or PDO. You’ll be able to tell by looking at the way that the database connection is made. The query() function that you are using is available in both libraries so that doesn’t narrow it down unfortunately.
BTW, please edit your code to display so it’s more easily readable. Put three backticks on a line immediately before the code section, and the same again on a line immediately afterwards. The three backticks need to be on a line on their own, not part of the code.