数据字段为:id(自增)、title(varchar(50)、content(longtext)
代码为
$title = $_POST['title']; (值为:titletest)
$content =$_POST['content'];(值为:contenttest )
$insert = "insert into article(title,content) values(".$title.','.$content.")";
错误为:Unknown column 'titletest' in 'field list'
代码为
$title = $_POST['title']; (值为:title test)这个和上面的多一个空格
$content =$_POST['content'];(值为:contenttest )
$insert = "insert into article(title,content) values(".$title.','.$content.")";
错误为:
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 'test,contenttest)' at line 1
将$insert = "insert into article(title,content) values(".$title.','.$content.")";
中的$title, $content 换成字符串就可以插入
回复讨论(解决方案)
语句有问题, 换成这样 $insert = "insert into article(title,content) values('$title','$content')";
sql串得有问题,试试这个 $insert = "insert into article(title,content) values('".$title."','".$content."')";
$insert = "insert into article (title,content) values(‘$title','$content’)";
语句有问题, 换成这样 $insert = "insert into article(title,content) values('$title','$content')";
谢谢,看来我还是太垃圾,这个简单的问题搞了1个多小时,是不是变量本身需要一个引号呢?