这是我的代码:
include "db_conx.php";
$sql = mysqli_query("INSERT INTO table(column) VALUES('" . mysqli_real_escape_string($var) . "')");
if ($sql) {echo "connection successful";
} else {
echo "failure";
}
它会返回以下错误:
Warning: mysqli_real_escape_string() expects exactly 2 parameters, 1 given
Warning: mysqli_query() expects at least 2 parameters, 1 given
我尝试使用PDO,但这也不起作用......
答案 0 :(得分:0)
第一个参数是mysql连接链接标识符,第二个是字符串有关详细信息,您可以访问此链接:http://in2.php.net/manual/en/mysqli.real-escape-string.php。
include "db_conx.php";
$sql = mysqli_query(pass_your_connection_identifier_here ,"INSERT INTO table(column) VALUES('" . mysqli_real_escape_string(pass_your_connection_identifier_here, $var) . "')");
if ($sql) {echo "connection successful";
} else {
echo "failure";
}
答案 1 :(得分:0)
您在mysqli_real_escape_string()
和mysqli_query()
中都缺少连接标识符
将您的代码更改为mysqli_query($connection,$sql)
和mysqli_real_escape_string($connection,$string)
答案 2 :(得分:0)
您在两条线路上都缺少连接变量,这就是您遇到问题的原因:
尝试用以下代码替换您的代码:
//$con // it is your connection variable
include "db_conx.php";
$sql = mysqli_query($con,"INSERT INTO table(column) VALUES('" . mysqli_real_escape_string($con,$var) . "')");
if ($sql) {echo "connection successful";
} else {
echo "failure";
}