douzai6337 2013-09-21 20:02
浏览 56

登录不工作

I am following a tutorial to do a log in system but unfortunately things are not working for me. When I try to log in, I am always re-directed to the log in form again instead of the k_panel.php that I wish! I already checked the code like a trillion times with the one supplied on the tutorial, but still nothing...

I Firebugged it and I got this error:

"document.logform.pass is undefined " and it was pointing on this part of the validation code "if ( document.logform.pass.value == "" ) { ".

What does this mean?! What should I do?

I will post the complete code bellow so that anybody can have a better picture:

<?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>

And here is the code of the page where it should be heading into (k_panel.php):

this is the code I have on the page that it should be heading to:

<?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");
}
?>
  • 写回答

1条回答 默认 最新

  • dtr32221 2013-09-21 20:18
    关注

    Yes that will give this kind of error because "pass" kind of entity not exist in your form so, that will give undefined. "document.logform.pass is undefined " and it was pointing on this part of the validation code "if ( document.logform.pass.value == "" ) { "

    IF you check that you are using name "password" instead of "pass".

    Correct this line of code like ..

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

    IF you have still issue just let me know.

    Regards

    评论

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿