怎样把变量写入sql?

既然命令里面不能加参数,比如$query = "INSERT INTO 'note' ('id','content') VALUES ('',$last)";而其中的$last不会被识别。怎么办?
---------------------------------------------------------------

这样可以的。

$query = "INSERT INTO 'note' ('id','content') VALUES ('',".$last.")";
---------------------------------------------------------------

对$last加上单引号,即 '$last' 就可以了。我在MySQL上试过,不知你这里怎么样,就是这个同样的情况,用insert语句。
---------------------------------------------------------------

如果你的那个content是数值型的就不用那个‘如果不是你加上就可以用了。

$query = "INSERT INTO 'note' ('id','content') VALUES ('','$last')";

---------------------------------------------------------------

那就这样。
$query = "INSERT INTO 'note' ('id','content') VALUES ('','$last')";

$query = "INSERT INTO 'note' ('id','content') VALUES ('','".$last."')";

不行就看看是不是有不可为空的字段你没有给值。

---------------------------------------------------------------

$query = "INSERT INTO note (id, content) VALUES ('','$last')";
就可以了,字段名是不能加引号的

---------------------------------------------------------------

$query = "INSERT INTO 'note' ('id','content') VALUES ('','".$last."')";

如果$last中出现'怎么办?

不知道可以实现否。。。
$query = "INSERT INTO note (id, content) VALUES ('','$last')";

如果可以的话,最好采用它

Published At
Categories with Web编程
comments powered by Disqus