-1

我正在按照教程进行登录系统,但不幸的是,事情对我不起作用。当我尝试登录时,我总是会再次重定向到登录表单,而不是我希望的 k_panel.php!我已经用教程中提供的代码检查了代码一万亿次,但仍然没有......

我 Firebugged 它,我得到了这个错误:

“document.logform.pass 未定义”,它指向验证代码的这一部分“if (document.logform.pass.value == "") {"。

这是什么意思?!我应该怎么办?

我将在下面发布完整的代码,以便任何人都可以更好地了解:

<?php
if ($_POST['email']) {
//Connect to the database through our include 
include_once "connect_to_mysql.php";
$email = stripslashes($_POST['email']);
$email = strip_tags($email);
$email = mysql_real_escape_string($email);
$password = ereg_replace("[^A-Za-z0-9]", "", $_POST['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 email='$email' AND password='$password' AND 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["id"];   
        session_register('id'); 
        $_SESSION['id'] = $id;
        // Get member username into a session variable
        $username = $row["username"];   
        session_register('username'); 
        $_SESSION['username'] = $username;
        // Update last_log_date field for this member now
        mysql_query("UPDATE members SET lastlogin=now() WHERE id='$id'"); 
        // Print success message here if all went well then exit the script
        header("location: k_panel.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="#fd0404", line-height:30px; vertical-align:middle; color:#fff; font-weight:bold;">Du finns inte i vårt system. Var vänlig och försök igen!</font><br />
<br /><a href="login.php">Klicka här</a> för att logga in.';
  exit();
}
}// close if post
?>

<!DOCTYPE html>
<head>
<!-- Form Validation -->
<script type="text/javascript">
function validate_form ( ) { 
valid = true; 
if ( document.logform.email.value == "" ) { 
alert ( "Var vänlig och skriv ditt användarnamn!" ); 
valid = false;
}
if ( document.logform.pass.value == "" ) { 
alert ( "Var vänlig och skriv ditt lösenord!" ); 
valid = false;
}
return valid;
}
</script>
<!-- Form Validation -->
</head>
<body>
<form action="login.php" method="post" enctype="multipart/form-data" name="logform" id="logform" onsubmit="return validate_form ( );">
             Skriv ditt e-post adress här:<br>
             <input name="email" type="text" id="email" size="30" maxlength="64" class="user"/><br><br>

             Skriv ditt lösenord här:<br>
             <input name="password" type="password" id="password" size="30" maxlength="24" class="pass"/><br><br>

             <input type="submit" name="submit" value="Login" class="login">

           </form>
</body>
</html>

这是它应该进入的页面的代码(k_panel.php):

这是我在页面上应该指向的代码:

<?php
session_start(); // Must start session first thing
// See if they are a logged in member by checking Session data
$toplinks = "";
if (isset($_SESSION['id'])) {
    // Put stored session variables into local php variable
    $username = $_SESSION['username'];
    $toplinks = '<p style="background:#48c248; line-height:30px; vertical-align:middle; color:#fff; font-weight:bold;">Välkomen . $username . </a> | <a href="logout.php">Log Out</a></p>';
} else {
    header("Location: login.php");
}
?>
4

1 回答 1

1

是的,这将产生这种错误,因为您的表单中不存在“通过”类型的实体,所以这将给出未定义的。“document.logform.pass 未定义”,它指向验证代码的这一部分“if (document.logform.pass.value == "") {"

如果您检查您使用的是名称“password”而不是“pass”。

更正这行代码,如 ..

if ( document.logform.password.value == "" ) { 

如果您仍有问题,请告诉我。

问候

于 2013-09-21T20:18:03.523 回答