我的代码出了什么问题?我确定$_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;
}
?>
答案 0 :(得分:2)
将INSERT INTO user (userList) VALUES ('$data');
放在双引号中。
例如:
$q = "INSERT INTO user (userList) VALUES ('$data')";
答案 1 :(得分:1)
PHP字符串文字必须在引号中。
要通过仅更改一行来解决此问题:
$q = "INSERT INTO user (userList) VALUES ('" . mysqli_real_escape_string($data . "')";
答案 2 :(得分: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