我用PHP for MySQL做了这个查询:
$query = "SELECT `username` FROM `usersdata` (select @user := van FROM `usersdata`) WHERE `username` = @user AND `password` = ? ";
但它会出现此错误:
致命错误:在第14行的/Applications/XAMPP/xamppfiles/htdocs/healthyfoodsite/authentication.php中调用非对象的成员函数
bind_param()
。
如何在PHP中为MySQL创建一个简单的变量?我做错了什么?我需要在一个查询中完成所有操作。
以下是我的所有代码:
require('db.php');
if(isset($_POST['submit'])){
if(isset($_POST['username']) && isset($_POST['password'])){
global $connection;
$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT `username` FROM `usersdata` (select @user := van FROM `usersdata`) WHERE `username` = @user AND `password` = ? ";
$stmt = $connection->prepare($query);
$stmt->bind_param("ss",$username,$password);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows > 0){
$stmt->bind_result($username);
while($stmt->fetch()){
echo $username;
}
}else{
echo "nothing happen";
}
}else{
header('location: ');
}
}
?>