loxfear Posted August 29, 2013 Share Posted August 29, 2013 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, Quote Link to comment Share on other sites More sharing options...
Solution fastsol Posted August 29, 2013 Solution Share Posted August 29, 2013 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. Quote Link to comment Share on other sites More sharing options...
loxfear Posted August 29, 2013 Author Share Posted August 29, 2013 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); ?> Quote Link to comment Share on other sites More sharing options...
requinix Posted August 29, 2013 Share Posted August 29, 2013 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. Quote Link to comment Share on other sites More sharing options...
loxfear Posted August 29, 2013 Author Share Posted August 29, 2013 No you're right: it's not possible. fastsol gave you the answer: so ill have to get rid of the auto-increment and use the mysql_insert_id() instead? Quote Link to comment Share on other sites More sharing options...
fastsol Posted August 29, 2013 Share Posted August 29, 2013 No, the auto-increment is part of the db, mysqli_insert_id() is a php function that provides the last id generated right after a query is run. Read up on it http://us3.php.net/manual/en/mysqli.insert-id.php 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.