使用php删除sql数据时出现语法错误

时间:2014-05-05 21:28:29

标签: php sql

我得到以下语法错误可以有人请帮忙! 我猜它太容易了,但我已经看了很久,可以看到我做错了什么

<?php
if(isset($_POST['delete']))
{
$dbhost = '';
$dbuser = '';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
  die('Could not connect: ' . mysql_error());
}

$CourseId = $_POST['CourseId'];

$sql = "DELETE  course ".
       " WHERE CourseId = $CourseId" ;

mysql_select_db('d11os_projectdb');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die('Could not delete data: ' . mysql_error());
}
echo "Deleted data successfully\n";
mysql_close($conn);
}
else
{
?>`enter code here` 

2 个答案:

答案 0 :(得分:3)

$sql = "DELETE FROM  course ".       --<-- Missing key word FROM
       " WHERE CourseId = $CourseId"

答案 1 :(得分:0)

您缺少sql查询中的表名

$sql = "DELETE  course FROM **table_name**".
       " WHERE CourseId = $CourseId" ;