Jump to content

getting the auto generated number


Go to solution Solved by fastsol,

Recommended Posts

hello,

 

i am currently working on a system that sends an email to the person who orders something,

in the order, there needs to be an order id. at the moment the id is generated when the information is put into the server.

 

when the form is filled, it submits to the php file, and in that file it sends to the server and in the same time it sends the email,

so my problem here is, how do i get that order id into the email,?

 

sorry for the verry unprofessional way i ask this question, 

Link to comment
https://forums.phpfreaks.com/topic/281671-getting-the-auto-generated-number/
Share on other sites

  • Solution

Is the ID the unique ID for the row in the database for a auto-incremented field?  If so you can use something like mysql_insert_id() or the equivalent of that if you are using PDO or mysqli.  Beyond that you will need to provide more info as to how you are getting that ID or how it's being built.

im thinking, becaus the id is from an auto-incremented field i cant get the id before it is created, or is that possible?

 

 

Here is the code i use:

im changeing some of it, since i want the email to be in an table, but that doesnt matter since my question is how my id can get into the email :)

$con=mysqli_connect();
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

$sql="INSERT INTO Persons (Fra, Til, Voksne, Born, Navn, Adresse, Byen, Telefon, Email, Kommentar)
VALUES
('$_POST[fra]','$_POST[til]','$_POST[voksne]','$_POST[born]','$_POST[navn]','$_POST[adresse]','$_POST[by]','$_POST[telefon]','$_POST[email]','$_POST[kommentar]')";
  {
  $email = $_POST['email'] ;
  $subject = $_POST['navn'] ;
  $navn = $_POST['navn'] ;
  $adresse = $_POST['adresse'] ;
  $by = $_POST['by'] ;
  $telefon = $_POST['telefon'] ;
  $email = $_POST['email'] ;
  $fra = $_POST['fra'] ;
  $til = $_POST['til'] ;
  $voksne = $_POST['voksne'] ;
  $born = $_POST['born'] ;
  $kommentar = $_POST['kommentar'] ;
  $time	 	= $_SERVER['REQUEST_TIME'];//Onix Time Format
  $tid = date('d-m-Y H:i:s', $time);
  
  mail("sand@soller.dk","bestilling fra: " . $subject,
  $navn . "\n" . $adresse . "\n" . $by . "\n" . $telefon . "\n" . $email . "\n\n" . "Fra dato: " . $fra . "\n" . "Til dato: " . $til . "\n" . "Bestilt: " . $tid . "\n\n" . "Antal voksne: " . $voksne . "\n" . "Antal børn: " . $born . "\n\n" . "Bemærkninger: " . $kommentar, "Du har fået en ny Leje Bestilling: ");
  
  mail($email,"bestillings bekreftigelse til: " . $subject,
  $navn . "\n" . $adresse . "\n" . $by . "\n" . $telefon . "\n" . $email . "\n\n" . "Fra dato: " . $fra . "\n" . "Til dato: " . $til . "\n" . "Bestilt: " . $tid . "\n\n" . "Antal voksne: " . $voksne . "\n" . "Antal børn: " . $born . "\n\n" . "Bemærkninger: " . $kommentar, "Denne bestilling blev sendt: ");
  
  }
if (!mysqli_query($con,$sql))
  {
  die('Error: ' . mysqli_error($con));
  }
echo "Din Bestilling er sendt!";

mysqli_close($con);
?>

im thinking, becaus the id is from an auto-incremented field i cant get the id before it is created, or is that possible?

No you're right: it's not possible.

 

fastsol gave you the answer:

use something like mysql_insert_id() or the equivalent of that if you are using PDO or mysqli.

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.