执行插入时查询出错

时间:2011-08-15 02:23:03

标签: php mysql mysqli

这是我的代码,我得到错误查询mssg:

 $name = mysqli_real_escape_string($dbc, trim($_POST['fname']));
 $emailid = mysqli_real_escape_string($dbc, trim($_POST['emailid']));
 $city = mysqli_real_escape_string($dbc, trim($_POST['city']));
 $comment = mysqli_real_escape_string($dbc, trim($_POST['comment']));
 $query="INSERT INTO userdate('name','city','emailid','pledge','date') VALUES       ('$name','$city','$emailid','$comment',NOW())";
$result=mysqli_query($dbc, $query) or die('error query'); 

1 个答案:

答案 0 :(得分:6)

您的查询中有单引号而非反引号。

$query="INSERT INTO userdate('name','city','emailid','pledge','date') VALUES ('$name','$city','$emailid','$comment',NOW())";

应该是:

$query="INSERT INTO userdate(`name`,`city`,`emailid`,`pledge`,`date`) VALUES ('$name','$city','$emailid','$comment',NOW())";