loxfear Posted August 29, 2013 Share Posted August 29, 2013 as you can see in my code, the line: $con->query($sql); for some reason gets the info posted on my database twise, and i have no reason why and how to fix this? <?php $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); $con->query($sql); mail("joachim@loxfear.com","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: " . $con->insert_id); } if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "Din Bestilling er sendt!"; mysqli_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/281681-a-line-in-my-code-sends-double-to-my-db/ Share on other sites More sharing options...
Love2c0de Posted August 29, 2013 Share Posted August 29, 2013 Good evening, I believe you are executing the query twice. Here: $con->query($sql); and Here: if (!mysqli_query($con,$sql)) I'd guess you were meant to be checking the return value of query instead of running the query again. Kind regards, L2c. Link to comment https://forums.phpfreaks.com/topic/281681-a-line-in-my-code-sends-double-to-my-db/#findComment-1447394 Share on other sites More sharing options...
loxfear Posted August 29, 2013 Author Share Posted August 29, 2013 so the answer would be, move the email code to the end and remove the first query? Link to comment https://forums.phpfreaks.com/topic/281681-a-line-in-my-code-sends-double-to-my-db/#findComment-1447396 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.