-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");
}
?>
** ** BTW我已經編輯我的主要問題,現在你可以看到它應該標題進入頁面上的代碼。 – viriato
我已經做了你所說的,除了現在我有另一個bug:「賦值到未聲明的變量有效」,它指向這部分代碼:「function validate_form(){ valid = true;」 – viriato