Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysqli_prepare()查询在localhost上工作,但在线上载时不工作,在准备好的语句上使用变量_Php_Mysql_Mysqli_Prepared Statement - Fatal编程技术网

Php mysqli_prepare()查询在localhost上工作,但在线上载时不工作,在准备好的语句上使用变量

Php mysqli_prepare()查询在localhost上工作,但在线上载时不工作,在准备好的语句上使用变量,php,mysql,mysqli,prepared-statement,Php,Mysql,Mysqli,Prepared Statement,我目前正在做一个客户网站的物品清单登录系统 在测试登录表单时,我不断在线收到这些错误: 警告:mysqli_stmt::bind_param()[mysqli stmt.bind param]:变量数量与第44行/home/greyan/public_html/shoplogin/login.php中准备好的语句中的参数数量不匹配 致命错误:在第48行的/home/greyan/public_html/shoplogin/login.php中调用未定义的方法mysqli_stmt::get_re

我目前正在做一个客户网站的物品清单登录系统

在测试登录表单时,我不断在线收到这些错误:

警告:mysqli_stmt::bind_param()[mysqli stmt.bind param]:变量数量与第44行/home/greyan/public_html/shoplogin/login.php中准备好的语句中的参数数量不匹配

致命错误:在第48行的/home/greyan/public_html/shoplogin/login.php中调用未定义的方法mysqli_stmt::get_result()

困扰我的是,只有当我在web服务器上在线上传时才会发生这种情况,而不是当我通过localhost查看站点时

//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = trim($str);
global $conn;
return $conn->real_escape_string($str);
}


//Sanitize the POST values
$username = clean($_POST['username']);
$password = clean($_POST['password']);

//Input Validations
if($username == '') {
$errmsg_arr[] = '*Username missing';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = '*Password missing';
$errflag = true;
}

//If there are input validations, redirect back to the login form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: index.php");
exit();
}

$sql = $conn->prepare("SELECT * FROM users WHERE username = '$username' AND password = '$password' ") ;
$sql->bind_param("ss", $username, $password) ;

$sql->execute();

$result = $sql->get_result();

我真的很困惑为什么这些错误不断发生。如bind_param()参数所述,准备好的语句中的变量数似乎是正确的。

不要转义字符串,用问号(?)替换变量名“$username”和“$password”。另外,不要使用单引号


作为安全预防措施,我还建议使用password_hash函数,因为您可能将密码存储为纯文本。

另一个困惑是,尽管您使用的是预先准备好的语句,但您正在转义数据。为准备好的语句转义数据会适得其反,当从db读回数据时,您将更改数据并看到转义字符。您的查询实际上不使用
占位符,而是插入两个变量。这就是错误消息的内容。很抱歉,我目前是mysqli的新手,我只是遵循了前面的查询示例,并在准备好的语句上进行了登录安全性实验。非常感谢您的回复!稍微修正了我的答案。谢谢!我目前还不熟悉mysql和php,这确实帮助我解决了问题。无需请求许可,只需请求即可。:)非常感谢您的快速回复!我的另一个问题是,我的Web服务器使用PHP5.3.29。根据我的研究,password_散列函数只在(PHP5>=5.5)上工作。然后我发现了另一个选择,即crypt函数。我还发现bcrypt是散列用户输入的最安全的方法之一。所以我的问题是,是否有任何方法可以使用phpmyadmin使用bcrypt对mysql数据库中的当前密码进行散列?或者任何类型的散列,使我能够与crypt()对用户输入进行散列时所做的比较。