-1

到目前为止,我已经从答案中编辑了代码,但我收到了这些错误

警告:mysqli_num_rows() 期望参数 1 为 mysqli_result,布尔值在第 18 行的 C:\xampp\htdocs\Test\index.php 中给出

警告:mysqli_fetch_array() 期望参数 1 为 mysqli_result,布尔值在第 28 行的 C:\xampp\htdocs\Test\index.php 中给出

第 18 行 - $checkuser= mysqli_num_rows($query);

28号线—— while ($row = mysqli_fetch_array($query)) {

 <?php



require_once('config.php');  


if(isset($_POST['Login']) && isset($_POST['uname']) && isset($_POST['pass1'])) {
// Here check if all input are sent 

$uname = $sql-> real_escape_string($_POST['uname']);
$pass1 = $sql-> real_escape_string($_POST['pass1']);


 if ( !empty($uname) && !empty($pass1)) {
  // Check if you input are not empty

  $query= mysqli_query($sql, "SELECT uname, pass1 FROM login WHERE uname='$uname'");
  $checkuser= mysqli_num_rows($query);


  if($checkuser != 1) {


   $error = "Username doesn't exist in our database!";
  }

  // Change $login with $query
  while ($row = mysqli_fetch_array($query)) {
   $checkpass= $row['pass1'];
    

   // here i changed $pass1 to $checkpass
   if ($pass1 == $checkpass) {


    setcookie("user", $uname, time()+7200);
    $_SESSION['user'] = $uname;
    $_SESSION['start'] = time();
    $_SESSION['expire'] = $_SESSION['start'] + (60 * 60 * 60);
    header("Location: main.html");
    exit();
   } else {


    $error = "Incorrect password!";
   }
  }
 } else {

 $error = "Please enter a username and password.";
 }
}



?>
4

2 回答 2

0
<input type="button" value="Login" name="Login" /> 

需要是

<input type="submit" value="Login" name="Login" /> 

或者

<button type="submit" name="Login">Login</button>

您拥有它的方式需要Javascript才能在单击按钮时提交表单。

除非您有其他提交表单的机制,否则这很可能是您的表单未提交的原因。除此之外,您需要更具体地说明您遇到的任何问题。

于 2013-08-13T19:39:01.817 回答
-2

试试这个并告诉我们是否有一些消息:

require_once('config.php');  


if (isset($_POST['Login']) && isset($_POST['uname']) isset($_POST['pass1'])) {
// Here check if all input are sent 

$uname = mysqli_real_escape_string($_POST['uname']);
$pass1 = mysqli_real_escape_string($_POST['pass1']);


 if ( !empty($uname) && !empty($pass1)) {
  // Check if you input are not empty

  $query= mysqli_query("SELECT uname FROM login WHERE uname='$uname'");
  $checkuser= mysqli_num_rows($query);


  if($checkuser != 1) {


   $error = "Username doesn't exist in our database!";
  }

  // Change $login with $query
  while ($row = mysqli_fetch_array($query)) {
   $checkpass= $row['pass1'];


   // here i changed $pass1 to $checkpass
   if ($pass1 == $checkpass) {


    setcookie("user", $uname, time()+7200);
    $_SESSION['user'] = $uname;
    $_SESSION['start'] = time();
    $_SESSION['expire'] = $_SESSION['start'] + (60 * 60 * 60);
    header("Location: main.html");
    exit();
   } else {


    $error = "Incorrect password!";
   }
  }
 } else {

 $error = "Please enter a username and password.";
 }
}


?>
于 2013-08-13T19:44:07.407 回答