Php没有检查行

时间:2017-07-31 10:46:01

标签: php mysql

我试图在php中登录表单,但我无法让它正常工作。

    <?php

include("connect.php");

$username = mysqli_real_escape_string($_GET['username']);
$password = mysqli_real_escape_string($_GET['password']);

$squery = mysqli_query("SELECT * FROM users WHERE username='$username'");
$query = mysqli_fetch_array($squery);
$rowcount = mysqli_stmt_num_rows($squery);

if($rowcount == 1)
{
    if($password != $query['password'])
        echo'Password is wrong';
    else
        echo 'Login succesful';
}
else
    echo 'Account is not registered';
?>

这就是我想要做的,但我不知道我做错了什么。我也检查了我的连接细节,这是正确的。

  

警告:mysqli_real_escape_string()需要2个参数,第5行/var/www/html/login.php中给出1个参数

     

警告:mysqli_real_escape_string()需要2个参数,第6行/var/www/html/login.php中给出1个

     

警告:mysqli_query()需要至少2个参数,第8行/var/www/html/login.php中给出1个参数

     

警告:mysqli_fetch_array()要求参数1为mysqli_result,在第9行/var/www/html/login.php中给出null

     

警告:mysqli_stmt_num_rows()要求参数1为mysqli_stmt,在第10行的/var/www/html/login.php中给出null

我已经用这个替换了包括:

$host = "127.0.0.1";
$user = "root";
$pass = "str0ng98x006";
$database = "userdb";
$conn = new mysqli($host, $user, $pass, $database);

2 个答案:

答案 0 :(得分:0)

<强>更改

1)在所需的mysqli函数中使用数据库连接变量。

更新代码

假设$conn为数据库连接变量,您将在包含(&#34; connect.php&#34;); 文件。

<?php

include("connect.php");

$username = mysqli_real_escape_string($conn, $_GET['username']);
$password = mysqli_real_escape_string($conn, $_GET['password']);

$squery = mysqli_query($conn, "SELECT * FROM users WHERE username='$username'");
$query = mysqli_fetch_array($squery);
$rowcount = mysqli_stmt_num_rows($squery);

if($rowcount == 1){
  if($password != $query['password'])
    echo'Password is wrong';
  else
    echo 'Login succesful';
} else {
  echo 'Account is not registered';
}
?>

答案 1 :(得分:0)

您必须在查询功能中传递连接变量 -

$squery = mysqli_query($conn, "SELECT * FROM users WHERE username='$username'");

和另一个错误应该是这样的 -

$rowcount = mysqli_num_rows($query);