-1

我的代码有什么问题?我确定$_POST['item']有有效的价值

<?php

$data = $_POST['item'];

$conn = mysqli_connect("localhost","root","");
mysqli_select_db($conn, "ajaxexample");

$q = INSERT INTO user (userList) VALUES ('$data');
if(mysqli_query($conn, $q)){

echo 1;

}

?>
4

3 回答 3

2

加上INSERT INTO user (userList) VALUES ('$data');双引号。

例如:

$q = "INSERT INTO user (userList) VALUES ('$data')";
于 2013-09-21T05:56:55.893 回答
1

PHP 字符串文字需要用引号引起来。

要通过仅更改一行来解决此问题:

$q = "INSERT INTO user (userList) VALUES ('" . mysqli_real_escape_string($data . "')";
于 2013-09-21T05:57:31.463 回答
0
<?php

$data = $_POST['item'];

$conn = mysqli_connect("localhost","root","", "ajaxexample");

$q = INSERT INTO user (userList) VALUES ('$data');
if(mysqli_query($conn, $q)){

echo 1;

}

?>

Not mysqli_select_db
于 2013-09-21T09:34:10.737 回答