-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>
从一瞥:你在你的查询中缺少一个关闭')'。无论如何,我宁愿准备好声明。 – Sirko
@Sirko我看不到一个丢失的“)”,它也在错误“行1”中说我认为是最奇怪的部分原因,只有说“<?php” –
“行1”是指行1你是SQL查询,而不是你的PHP文件的第一行。 – wogsland