我收到此錯誤:我得到一個錯誤在MySQL中可以any1幫助我嗎?
UPDATE subjects SET menu_name = 'Delete me', position = 4, visible = 1, WHERE id = 6 Database query failed: 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 'WHERE id = 6' at line 1
<?php
//1. create a database connection
$dbhost = "localhost";
$dbuser = "widget_cms";
$dbpass = "funkyguy";
$dbname = "widget_corp";
$connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
// Test database connection
if(mysqli_connect_errno()) {
die("database connection failed: " .
mysqli_connect_error() .
"(" . mysqli_connect_errno() . ")"
);
}
?>
<?php
//this are the form values from $_POST
$id = 6;
$menu_name = "Delete me";
$position = 4;
$visible = 1;
//2. perform database query
$query = "UPDATE subjects SET ";
$query .= "menu_name = '{$menu_name}', ";
$query .= "position = {$position}, ";
$query .= "visible = {$visible}, ";
$query .= "WHERE id = {$id}";
echo $query;
$result = mysqli_query($connection, $query);
// test if there was a query error
if($result) {
echo "success";
}else {
die(" Database query failed: " . mysqli_error($connection));
}
?>
<!doctype html>
<html lang="en">
<head>
<title>Database</title>
</head>
<body>
</body>
</html>
<?php
//5. Close the connection
mysqli_close($connection);
?>
刪除查詢前的逗號。 –