数据库正常,权限正常,在mysql里可以正常查询到结果。
但是php里就返回null。
<?php
session_start();
if (isset($_POST['userid']) && isset($_POST['password'])) {
  $userid= $_POST['userid'];
  $password= $_POST['password'];
  $db_conn =  new mysqli('localhost', 'webauth', 'webauth', 'auth');
  var_dump($db_conn);
  if (mysqli_connect_errno()) {
    echo 'Connection failed'.mysqli_connect_errno();
    exit();
    # code...
  }
  $query= 'select count * from authorized_users'."where name= '".$userid."'"."&& password= sha1('".$password."')";
  $result= $db_conn->query($query);
  if ($result->num_rows) {
    $_SESSION['valid_user']= $userid;
    # code...
  }
  $db_conn->close();
}
?>
<html>
<body>
<h1>Home page</h1>
<?php
if (isset($_SESSION['valid_user'])) {
  echo "You are logged in as: ".$_SESSION['valid_user'].'<br />';
  echo '<a href= "logout.php">Log Out</a>';
}
else{
  if(isset($userid)){
    echo 'Could not log you in.<br />';
  }
  else {
    echo 'You are not logged in.<br />';
  }
  echo '<form method= "post" action= "authmain.php">';
  echo '<table>';
  echo '<tr><td>Userid: </td>';
  echo '<td><input type= "text" name= "userid"></td></tr>';
  echo '<tr><td>Password: </td>';
  echo '<td><input type= "password" name= "password"></td></tr>';
  echo '<tr><td colspan= "2" align= "center">';
  echo '<input type= "submit" value= "log in"></td></tr>';
  echo '</table></form>';
}
?>
<br />
<a href="members_only.php">Members section</a>
</body>
</html>
|      1hcymk2      2014-10-23 17:32:28 +08:00 select count * from authorized_users  mysql 可以这样写 count ? | 
|  |      2jacob OP | 
|  |      3Delbert      2014-10-23 17:40:40 +08:00  1 'select count * from authorized_users' -> 'select count * from authorized_users '试试。 中间没有空格的话就成了 authorized_userswhere 而不是 authorized_users where 了吧? 无责任猜测。 | 
|  |      5muziyue      2014-10-24 10:55:01 +08:00 这种bug打印一下sql语句就完事了 |