2016-02-13 50 views
-1

我想連接到我的MySQL數據庫,但我得到錯誤1604 (Error: 1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1)。我不知道這是怎麼發生的,因爲它從未發生過。它只是隨機開始。錯誤:1064 MySQL隨機啓動

這裏是我的代碼:

<?php 
// Only process the form if $_POST isn't empty 
if (! empty($_POST)) { 

    // Connect to MySQL 
$mysqli = new mysqli('***', '***', '***', '***'); 
// Check our connection 
if ($mysqli->connect_error) { 
die('Kan niet verbinden met database. Probeer het later opnieuw. ' . $mysqli->connect_errno . ': ' . $mysqli->connect_error); 
} 

// Insert our data 

$sql = "INSERT INTO inschrijven (naam, email, aantal,ip) VALUES ('{$mysqli->real_escape_string($_POST['naam'])}', '{$mysqli->real_escape_string($_POST['email'])}', '{$mysqli->real_escape_string($_POST['aantal'])}','{$mysqli->real_escape_string($_SERVER['REMOTE_ADDR'])}'"; 
    // validate agree unless you want to add 'checked' to one of the values 

    $insert = $mysqli->query($sql); 


// Print response from MySQL 
if ($insert) { 
echo "U bent succesvol ingeschreven! U heeft bootnummer: {$mysqli->insert_id}. Op de naam: . U krijgt hiervan nog een bevesteging op uw mail, uw bootnummer kan nog veranderen. Hopelijk zien we u op de BotenBouwDag 2016!"; 
} else { 
die("Error: {$mysqli->errno} : {$mysqli->error}"); 
} 


$mysqli->close(); 
} 

?> 


<HTML> 
<head> 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 

<title> 
Welkom op de officiële site van de BotenBouwDag 2016 
</title> 
</head> 
<body> 

<form method="post" action=""> 
<input name="naam" id="naam" type="text"> 
<input name="email" id="email" type="email" autocomplete="off"> 
<input name="aantal" id="aantal" type="number"> 
<input type="radio" name="eten"> Ja 
<input type="radio" name="eten"> Nee 
<input type="submit" id="submit" value="Verstuur Informatie"> 
</form> 

<div id="ip"></div> 
<div id="address"></div> 
<script type="text/javascript"> 

$.get("http://ipinfo.io", function (response) { 
$("#ip").html("IP: " + response.ip); 



document.getElementById('city').value = response.city; 
}, "jsonp"); 
</script> 


</body> 
</HTML> 
+0

從一瞥:你在你的查詢中缺少一個關閉')'。無論如何,我寧願準備好聲明。 – Sirko

+0

@Sirko我看不到一個丟失的「)」,它也在錯誤「行1」中說我認爲是最奇怪的部分原因,只有說「<?php」 –

+0

「行1」是指行1你是SQL查詢,而不是你的PHP文件的第一行。 – wogsland

回答

1

您的查詢缺少一個)封閉VALUES第1行:

$sql = "INSERT INTO inschrijven (naam, email, aantal,ip) VALUES ('{$mysqli->real_escape_string($_POST['naam'])}', '{$mysqli->real_escape_string($_POST['email'])}', '{$mysqli->real_escape_string($_POST['aantal'])}','{$mysqli->real_escape_string($_SERVER['REMOTE_ADDR'])}'"; 

應該

$sql = "INSERT INTO inschrijven (naam, email, aantal,ip) 
     VALUES (
      '{$mysqli->real_escape_string($_POST['naam'])}', 
      '{$mysqli->real_escape_string($_POST['email'])}', 
      '{$mysqli->real_escape_string($_POST['aantal'])}', 
      '{$mysqli->real_escape_string($_SERVER['REMOTE_ADDR'])}' 
     )"; 
+0

ow哇...我很愚蠢...... Ty –