Jump to content

a line in my code sends double to my db


loxfear

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.