-5

此代码无法识别我数据库上的登录用户。我已经尝试了几件事,到目前为止都没有任何影响。有人可以指出错误吗

 <?php
 session_start();
 include("dbconnect.php");
 $numrows=0;
 $sqlMember = mysql_real_escape_string($_POST["Membership_Number"]);
$sqlPassword = mysql_real_escape_string($_POST["Password"]); 

 $query="SELECT First_name, Last_name, Membership_Number FROM members WHERE Membership_Number='$member' AND Password='$password'";


 $link = mysql_query($query);
 if (!$link) {
  die('login error');
 }
 $numrows=mysql_num_rows($link);
 if ($numrows>0){  // authentication is successfull
  while($row = mysql_fetch_array($query));
  $_SESSION['user']['first_name']=$row['first_name'];
  $_SESSION['user']['last_name']=$row['last_name'];
  $_SESSION['user']['Membership_Number ']=$row['Membership_Number '];
  echo $_SESSION['user']['fname'].' '.$_SESSION['user']['lname'];
  header("location:members_area.php");
 } else {
  header("location:../invalid.php");  // authentication was unsuccessfull
 }
?>

HTML

<form id="jjjj" action="Send_log_details.php" class="register" method="POST">
        <ul>
        <li>
        Membership Number:<br>
        <input type="text" id="Membership_Number" name="Membership_Number">
        </li>
        <li>
        Password:<br>
        <input type="password"  id="Password" name="Password" value="Log in">
        </li>
        <li>

        <input type="submit" name="register" value="Login" onclick="logMeIn()">             
        </li>
        </ul>
        </form>

谢谢你的帮助

4

2 回答 2

1

您有$link包含 MYSQL 查询的变量,并且您正在使用$query变量。

if ($numrows>0){
  while($row = mysql_fetch_array($link)) {
      $_SESSION['user']['first_name']=$row['first_name'];
      $_SESSION['user']['last_name']=$row['last_name'];
      $_SESSION['user']['Membership_Number']=$row['Membership_Number'];
  }
  echo $_SESSION['user']['fname'].' '.$_SESSION['user']['lname'];
  header("Location: members_area.php");

 } else {
  header("Location: ../invalid.php");
 }
于 2013-01-11T17:08:43.903 回答
0

这条线可能是问题所在:

$_SESSION['user']['Membership_Number ']=$row['Membership_Number '];

它应该是:

$_SESSION['user']['Membership_Number']=$row['Membership_Number'];

我已经从数组键名的末尾删除了空格。

于 2013-01-11T17:11:57.200 回答