我正在尝试使自己成为一个带有会员登录系统的简单 PHP 网站。我已经创建了网站的注册部分,并且条目成功更新/添加到我的 Mysql 数据库中。但是我只是无法让我的 login.php 使用详细信息登录。我的 login.php 的 php 代码如下;
<?php
if ($_POST['mem_email']) {
//Connect to the database through our include
include_once "storescripts/connect_to_mysql.php";
$email = stripslashes($_POST['mem_email']);
$email = strip_tags($email);
$email = mysql_real_escape_string($email);
$password = ereg_replace("[^A-Za-z0-9]", "", $_POST['mem_password']); // filter everything but numbers and letters
$password = md5($password);
// Make query and then register all database data that -
// cannot be changed by member into SESSION variables.
// Data that you want member to be able to change -
// should never be set into a SESSION variable.
$sql = mysql_query("SELECT * FROM members WHERE mem_email='$email' AND mem_password='$password' AND mem_emailactivated='1'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
// Get member ID into a session variable
$id = $row["mem_id"];
session_register('mem_id');
$_SESSION['mem_id'] = $id;
// Get member username into a session variable
$username = $row["mem_username"];
session_register('mem_username');
$_SESSION['mem_username'] = $username;
// Update last_log_date field for this member now
mysql_query("UPDATE members SET mem_lastlogin=now() WHERE mem_id='$id'");
// Print success message here if all went well then exit the script
header("location: member_profile.php?id=".$id);
exit();
} // close while
} else {
// Print login failure message to the user and link them back to your login page
print '<br /><br /><font color="#FF0000">No match in our records, try again </font><br />
<br /><a href="login.php">Click here</a> to go back to the login page.';
exit();
}
}// close if post
?>
位于同一页面上的表格如下;
<table align="center" cellpadding="5">
<form action="login.php" method="post" enctype="multipart/form-data" name="logform" id="logform" onsubmit="return validate_form ( );">
<tr>
<td class="style7"><div align="right">Email Address:</div></td>
<td><input name="mem_email" type="text" id="mem_email" size="30" maxlength="64" /></td>
</tr>
<tr>
<td class="style7"><div align="right">Password:</div></td>
<td><input name="mem_password" type="password" id="mem_password" size="30" maxlength="24" /></td>
</tr>
<tr>
<td> </td>
<td><input name="Submit" type="submit" value="Login" /></td>
</tr>
</form>
</table>
我的数据库看起来像这样
mem_id int(11)
mem_username varchar(255)
mem_country varchar(255)
mem_county varchar(255)
mem_address varchar(255)
mem_email varchar(255)
mem_password varchar(255)
mem_signupdate datetime
mem_lastlogin datetime
mem_accounttype enum('a', 'b', 'c')
mem_emailactivated enum('0', '1')
mem_postcode varchar(255)
mem_city varchar(255)
每次在我的登录表单中输入正确的数据时,我都会处理到带有失败消息的 else 语句