当我使用这个mysqli_real_escape_string()时,为什么我一直收到这个错误?
mysqli_real_escape_string() expects exactly 2 parameters, 1 given in C:\xampp\htdocs\beatbeast\reg.php on line 6
我已经传递了连接,以及需要清理的字符串,但是我怎么继续得到这个错误?
这是我的代码
<?php
class Db_DatabaseUtilities{
public static function registerAccount($conn,$username,$password,$email){
if(!isset($conn)){
echo"XDDDDDDDDD";
}
$username = mysqli_real_escape_string($conn,$username);
$email =mysqli_real_escape_string($conn,$username);
$password = mysqli_real_escape_string($conn,$password);
$hashedpass = crypt($password,$username);
$sql = "INSERT INTO accounts ('username','password','email') VALUES('{$username}','{$hashedpass}','{$email}')";
Db_DatabaseUtilities::perform_query($conn, $sql);
}
public static function perform_query($conn,$sql){
$result_set = $conn->query($sql);
if(!$result_set){
die("Die Database Query Failed");
}else{
return $result_set;
}
}
}
答案 0 :(得分:3)
首先:如果这是您真正的代码,那么您将逃避$username
两次而$email
完全没有:
$username = mysqli_real_escape_string($conn,$username);
$email =mysqli_real_escape_string($conn,$username);//should probably be $email as second param
您可以选择两个问题:
我看不到任何其他选择...... 祝你好运
答案 1 :(得分:0)
检查reg.php
的第6行。
string mysqli_real_escape_string ( mysqli $link , string $escapestr )
您需要将mysqli连接作为第一个参数传递。