我想從mysql數據庫中刪除數據。但是,當我查看代碼時,我收到以下錯誤無法刪除數據:您的SQL語法中有錯誤;檢查對應於你的MySQL服務器版本正確的語法使用手動附近「WHERE ProductsID = 30」在行1錯誤:無法刪除數據:您在'WHERE ProductsID = 30'附近的SQL語法中有錯誤任何想法?
<html>
<head>
<title>Delete a Record from MySQL Database</title>
</head>
<body>
<?--Code to delete-->
<?php
if(isset($_POST['delete']))
{
$dbhost = 'DatabaseHostName';
$dbuser = 'username';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn)
{
die('Could not connect: ' . mysql_error());
}
$ProductsID = $_POST['ProductsID'];
$sql = "DELETE Products ".
"WHERE ProductsID = $ProductsID" ;
mysql_select_db('dbname');
$retval = mysql_query($sql, $conn);
if(! $retval)
{
die('Could not delete data: ' . mysql_error());
}
echo "Deleted data successfully\n";
mysql_close($conn);
}
else
{
?>
<form method="post" action="<?php $_PHP_SELF ?>">
<table width="400" border="0" cellspacing="1" cellpadding="2">
<tr>
<td width="100">Products ID</td>
<td><input name="ProductsID" type="text" id="ProductsID"></td>
</tr>
<tr>
<td width="100"> </td>
<td> </td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="delete" type="submit" id="delete" value="Delete">
</td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
[DELETE語法](http://dev.mysql.com/doc/refman/5.5/en/delete.html)。錯誤信息非常清楚。你不需要發佈100行不相關的代碼。 – 2013-04-27 07:59:48