Jump to content


Photo

a line in my code sends double to my db


Best Answer Love2c0de, 29 August 2013 - 05:28 PM

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.

Go to the full post


  • Please log in to reply
2 replies to this topic

#1 loxfear

loxfear

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts
  • LocationDenmark
  • Age:21

Posted 29 August 2013 - 04:57 PM

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);
?>


#2 Love2c0de

Love2c0de

    Advanced Member

  • Members
  • PipPipPip
  • 366 posts
  • LocationThe Pleiades
  • Age:23

Posted 29 August 2013 - 05:28 PM   Best Answer

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.


Edited by Love2c0de, 29 August 2013 - 05:33 PM.


#3 loxfear

loxfear

    Advanced Member

  • Members
  • PipPipPip
  • 44 posts
  • LocationDenmark
  • Age:21

Posted 29 August 2013 - 05:43 PM

so the answer would be, move the email code to the end and remove the first query?






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com