mysqli_query()期望参数1是mysqli,在线给出的字符串

时间:2015-09-09 15:31:39

标签: php mysqli

我正在为我的项目做一个网站,但我的登录部分给了我问题,我正确输入了用户名和密码,但显示错误仍然...我已经尝试修复我的代码,但是我真的不确定问题是什么......这是我的代码:

<?php 
//connecting to db
$servername = "localhost";
$username = "root"; 
$pwd = ""; $db="SCUSER";
$connection = mysqli_connect($servername, $username, $pwd, $db);
if (mysqli_connect_errno()){
    echo "Connection was not established:". mysqli_connect_error();
 } 

if(isset($_POST["submit"])){
$eml = mysqli_real_escape_string($connection,$_POST["eml"]);
$pwd = mysqli_real_escape_string($connection,$_POST["pwd"]);

$query = "SELECT USERS_EMAIL, USERS_PWD FROM USERS WHERE USERS_EMAIL= $eml AND USERS_PWD= $pwd";
$result = mysqli_query($query, $connection);    //this is where i get the problem
$rows = mysqli_num_rows($result);    //and here too

if($rows > 0){
    //fetch results
    $row = mysqli_fetch_assoc($result);
    //check whether username and password correct
    if($row["USERS_EMAIL"] = $eml){
        if($_SESSION["pwd"] = $pwd){
            header("location: usrindex.php");
        }
        else{
            echo "Email or password incorrect!!";
        }
    }
    else{
        echo "User doesn't exist!!";
       }
   }
}
?>

错误显示在查询部分,但我真的不确定问题是什么,我希望有人会指导我或指出我做错的错误。 Ps:我还是php和mysqli的初学者,如果有人已经提出这个问题,我很抱歉

1 个答案:

答案 0 :(得分:0)

参数的顺序是错误的。应该是:

<preference name="AutoHideSplashScreen" value="false" />
  

程序风格

$result = mysqli_query($connection, $query);

http://php.net/manual/en/mysqli.query.php