我收到此错误:错误描述:
您的SQL语法有误;检查手册对应于您的MariaDB服务器版本以使用正确的语法第1行的“”附近
有人可以帮我吗?我已经上传了此代码中使用的文件。
Verbind.php =
<?php
//initialize variables
$Pand =" ";
$Naam =" ";
$Email =" ";
$Huisnummer =" ";
$Deel =" ";
$id = 0;
// connect to database
$db = mysqli_connect("xxx","xxx","xxx","xxx");
//update records
if (isset($_POST['aanpassen'])) {
$Naam = mysqli_real_escape_string($_POST["Naam"]);
$Email = mysqli_real_escape_string($_POST["Email"]);
$Pand = mysqli_real_escape_string($_POST["Pand"]);
$Huisnummer = mysqli_real_escape_string($_POST["Huisnummer"]);
$Deel = mysqli_real_escape_string($_POST["Deel"]);
$id = mysqli_real_escape_string($_POST["id"]);
if (!mysqli_query($db,"UPDATE Info SET Naam= '$Naam' , Email= '$Email' , Pand= '$Pand' , Huisnummer= '$Huisnummer' , Deel= '$Deel' WHERE id=$id")){
echo("Error description:". mysqli_error($db));
}
header('location: overzichtlocatie.php');
}
// retrieve records
$results = mysqli_query($db, "SELECT * FROM Info");
?>
overzichtlocatie.php =
<?php include('verbind.php');
//fetch the records to be updates
if (isset($_GET['edit'])) {
$id = $_GET['edit'];
$rec = mysqli_query($db, "SELECT * FROM Info WHERE id=$id");
$record = mysqli_fetch_array($rec);
$Naam = $record['Naam'];
$Email = $record['Email'];
$Pand = $record['Pand'];
$Huisnummer = $record['Huisnummer'];
$Deel = $record['Deel'];
$id = $record['id'];
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Overzicht locatie</title>
<link rel="stylesheet" type="text/css" href="overzichtlocatie.css">
</head>
<body>
<table>
<thead>
<tr>
<th>Naam</th>
<th>E-mail</th>
<th>Pand</th>
<th>Huisnummer</th>
<th>Deel</th>
<th>Aanpassen</th>
</tr>
</thead>
<tbody>
<?php while ($row = mysqli_fetch_array($results)){ ?>
<tr>
<td><?php echo $row['Naam']?></td>
<td><?php echo $row['Email']?></td>
<td><?php echo $row['Pand']?></td>
<td><?php echo $row['Huisnummer']?></td>
<td><?php echo $row['Deel']?></td>
<td>
<a href="overzichtlocatie.php?edit=<?php echo $row['id']; ?>">Aanpassen</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<form method="post" action="">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<div class="input-group">
<label>Naam</label>
<input type="text" name="Naam" value="<?php echo $Naam?>">
</div>
<div class="input-group">
<label>E-mail</label>
<input type="email" name="Email" value="<?php echo $Email?>">
</div>
<div class="input-group">
<label>Pand</label>
<input type="text" name="Pand" value="<?php echo $Pand?>">
</div>
<div class="input-group">
<label>Huisnummer</label>
<input type="text" name="Huisnummer" value="<?php echo $Huisnummer?>">
</div>
<div class="input-group">
<label>Deel</label>
<input type="text" name="Deel" value="<?php echo $Deel?>">
</div>
<div class="input-group">
<button type="submit" name="aanpassen" class="btn">Aanpassen</button>
</div>
</form>
</body>
</html>
您不正确地使用函数“ mysqli_real_escape_string()”
在以下链接中向下滚动到遮阳篷。您会看到mysqli和mysql函数之间的矛盾。Link - driffrent between mysqli and mysql function
该函数恰好需要两个参数。
看下面的代码:
//Open the Connection to mysql
$oCon = new mysqli('XXX', 'XXX', 'XXX', 'XXX');
if ($oCon->connect_error)
{
die("Connection failed: " . $oCon->connect_error);
}
//Like your Var. but with the connection Object
//Parm. 1 -> Connection Object, Parm 2 is your Value
$id = mysqli_real_escape_string($oCon,$_POST["id"]);
$Naam = mysqli_real_escape_string($oCon, $_POST["Naam"]);
//a shorter version of your sql Update.
if (!mysqli_query($oCon,"UPDATE Info SET Naam= '$Naam' WHERE id=$id")){
echo("Error description:". mysqli_error($oCon));
}
我希望这能解决您的问题。