把:
$sql="INSERT INTO liuyaninfo (id,title,content,author)
VALUES
('$_POST["id"]','$_POST["title"]','$_POST["content"]','$_POST["author"]')";
修改成:
$sql="INSERT INTO liuyaninfo (id,title,content,author)
VALUES
('".$_POST["id"]."','".$_POST["title"]."','".$_POST["content"]."','".$_POST["author"]."')";
$sql="INSERT INTO liuyaninfo (id,title,content,author)
VALUES
('".$_POST["id"]."','".$_POST["title"]."','".$_POST["content"]."','".$_POST["author"]."')";
用"."来拼接语句, 还有这个id是不是自增的, 自增的就不需要插入id, 如果不是自增的, 看是不是int类型, 如果是int类型,那这个值是不需要加单引号的
$sql="INSERT INTO liuyaninfo (title,content,author) VALUES ('$_POST["title"]','$_POST["content"]','$_POST["author"]')";
请先将id设置为int型,并设置为auto_increament
否则,就自行生成一个不重复的id,并插入
你看下是不是这个原因。
单引号内部的变量不会执行
双引号会执行
如
$name = 'hello';
echo "the $name";
会输出 the hello
而如果是单引号
$name = 'hello';
echo 'the $name';
会输出 the $name
建议你改成 $title = $_POST["title"];然后用$title写在sql上
引号这样写会有问题改成这样试试
$id = $_POST["id"];
$title = $_POST["title"];
$content = $_POST["content"];
$author = $_POST["author"];
$sql="INSERT INTO liuyaninfo (id,title,content,author)
VALUES ('$id','$title','$content','$author')";
如果还是写不进去,先echo一下这几个post变量是否有值