2014-02-24 50 views
-1

我有一個問題,我不知道問題出在哪裏從何而來,我的代碼:爲什麼它在數據庫中放入兩次值?

<?php 
session_start(); 
if(isset($_POST["verzenden1"])) 
{ 
    $Bestelling = "Gunsafe"; 
} 
if(isset($_POST["verzenden2"])) 
{ 
    $Bestelling = "5-6 wapens(sleutel)"; 
} 
if(isset($_POST["verzenden3"])) 
{ 
    $Bestelling = "5-6 wapens(toetsenbord)"; 
} 
if(isset($_POST["verzenden4"])) 
{ 
    $Bestelling = "8-16 wapens(sleutel)"; 
} 
if(isset($_POST["verzenden5"])) 
{ 
    $Bestelling = "8-16 wapens(toetsenbord)"; 
} 
if(isset($_POST["verzenden6"])) 
{ 
    $Bestelling = "Pistoolkluis"; 
} 
if(isset($_POST["versturen"])) 
{ 
    include 'Databankverbinden.php'; 

    $Bestelling1 = $_POST["Bestelling"]; 
    $Naam = $_POST["Naam"]; 
    $Adres = $_POST["Adres"]; 
    $Telefoon = $_POST["Telefoonnummer"]; 
    $Email = $_POST["Email"]; 
    if(isset($_POST['Levering']) && $_POST['Levering'] == 'Ja') 
    { 
     $sql = "INSERT INTO bestelling(Naam, Adres, Telefoon, Email, Bestelling, Levering) VALUES ('$Naam','$Adres','$Telefoon','$Email','$Bestelling1','1')"; 

     $result = mysql_query($sql) or die('query fout'); 
     if(!filter_var($Email, FILTER_VALIDATE_EMAIL)) 
     { 
      echo "<script>alert('E-mail is niet geldig!')</script>"; 
      echo "<script>document.location.href='Betaling.php'</script>"; 
     } 
     else 
     { 
      $to = "[email protected]"; 
      $subject = "Bestelling"; 
      $message = "De volgende persoon : $Naam \n Heeft besteld: $Bestelling1 \n Gegevens: \n Adres: $Adres \n Telefoon nummer : $Telefoon \n E-mail : $Email \n Deze persoon zou graag zijn kluis geleverd zien. "; 
      $from = "$Email"; 
      $headers = "From:" . $from; 
      mail($to, $subject, $message, $headers); 
      echo "<script>alert('Uw bestelling is geplaatst , klik op home als u weg wilt gaan.');</script>"; 
     } 
    } 
    else 
    { 
     $sql = "INSERT INTO bestelling(Naam, Adres, Telefoon, Email, Bestelling, Levering) VALUES ('$Naam','$Adres','$Telefoon','$Email','$Bestelling1','0')"; 
     $result = mysql_query($sql) or die('query fout'); 
     if(!filter_var($Email, FILTER_VALIDATE_EMAIL)) 
     { 
      echo "<script>alert('E-mail is niet geldig!')</script>"; 
      echo "<script>document.location.href='Betaling.php'</script>"; 
     } 
     else 
     { 
      $to = "[email protected]"; 
      $subject = "Bestelling"; 
      $message = "De volgende persoon : $Naam \n Heeft besteld: $Bestelling1 \n Gegevens: \n Adres: $Adres \n Telefoon nummer : $Telefoon \n E-mail : $Email \n Deze persoon zou graag zijn kluis komen afhalen. "; 
      $from = "$Email"; 
      $headers = "From:" . $from; 
      mail($to, $subject, $message, $headers); 
      echo "<script>alert('Uw bestelling is geplaatst , klik op home als u weg wilt gaan.');</script>"; 
     } 
    } 
    $result = mysql_query($sql) or die('query fout'); 
    if(!filter_var($Email, FILTER_VALIDATE_EMAIL)) 
    { 
     echo "<script>alert('E-mail is niet geldig!')</script>"; 
     echo "<script>document.location.href='Betaling.php'</script>"; 
    } 
    else 
    { 
     $to = "$Email"; 
     $subject = "Bestelling"; 
     $message = "Beste klant \n U heeft een bestelling geplaatst op titansafes. U wordt binnenkort gecontacteerd over uw bestelling ($Bestelling1). \n Met vriendelijke Groeten \n Titansafes"; 
     $from = "[email protected]"; 
     $headers = "From:" . $from; 
     mail($to, $subject, $message, $headers); 
    } 
} 
?> 

它把值兩次在數據庫中,如果「撬動」 = 1,它把它在數據庫,但這樣的:enter image description here並且如果在「撬動」 = 0,同樣的:enter image description here 我不知道爲什麼它是....

+3

神聖的垃圾,如此多的嵌套'if's ... –

+0

他們不嵌套 - 這只是不好的代碼格式。 – feeela

+0

它們是嵌套的嗎? –

回答

11

您對線下面的代碼(66)

$result=mysql_query($sql) or die('query fout'); 

這會再次執行您的SQL。

+1

事實上,這是我犯的錯誤,從我愚蠢的,我會upvote你的答案,但有人給我一個-1所以我不能:D哈哈哈,但還是謝謝你! – Bondjens

+1

只要你有你的答案:)我不知道接受的答案是如何工作的。通常在你左邊的箭頭下面有一個接受標記。 –

+0

哦,非常感謝你,以前從來不知道,現在我可以並且確實給了你一個upvote:D和接受答案! hahaha – Bondjens

相關問題