如何在php中为网络编程制作mysql变量(@variable)?

时间:2017-01-11 22:47:30

标签: php mysql

我用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: ');
    }
}
?>

0 个答案:

没有答案