我试图重定向到用户页面一旦使用输入登录ID和密码我写这样的代码
<?php
include ('.../database.php');
if (isset($_POST['formsubmitted'])) {
// Initialize a session:
session_start();
$error = array();//this array will store all error messages
if (empty($_POST['empno'])) {//if the email supplied is empty
$error[] = 'You forgot to enter your Employee No ';
}
else {
$email = $_POST['empno'];
}
if (empty($_POST['password'])) {
$error[] = 'Please Enter Your Password ';
} else {
$password = $_POST['password'];
}
if (empty($error))//if the array is empty , it means no error found
{
$query_check_credentials = "SELECT * FROM table WHERE (emp_no='$email' AND password='$password')";
$result_check_credentials = mysqli_query($dbc, $query_check_credentials);
if(!$result_check_credentials){//If the QUery Failed
echo 'Query Failed ';
}
if (@mysqli_num_rows($result_check_credentials) == 1)//if Query is successfull
{ // A match was made.
if(!isset($_SESSION['user'])) {
$_SESSION = mysqli_fetch_array($result_check_credentials, MYSQLI_ASSOC);//Assign the result of this query to SESSION Global Variable
header("Location: http://websiteaddress.com/folder/?page_id=800");
}
else
{
$msg_error= 'Either Your Account is inactive or Email address /Password is Incorrect';
}
}
else
{
echo '<div class="errormsgbox"> <ol>';
foreach ($error as $key => $values) {
echo ' <li>'.$values.'</li>';
}
echo '</ol></div>';
}
if(isset($msg_error)){
echo '<div class="warning">'.$msg_error.' </div>';
}
/// var_dump($error);
mysqli_close($dbc);
} // End of the main Submit conditional.
?>
Please enter your Employee ID and Password to sign in (both are case-sensitive).
<form action="" method="post" class="registration_form">
<fieldset>
<legend>Login Form </legend>
<p></p>
<div class="elements">
<label for="name">Employee No:</label>
<input type="text" id="e-mail" name="empno" size="25" />
</div>
<div class="elements">
<label for="Password">Password:</label>
<input type="password" id="Password" name="password" size="25" />
</div>
<div class="submit">
<input type="hidden" name="formsubmitted" value="TRUE" />
<input type="submit" value="Login" />
</div>
</fieldset>
</form>
我无法转到我的用户页面。每次我输入登录按钮。我的页面重新加载相同的URL,即登录页面。
答案 0 :(得分:0)
尝试更改条件,
if(isset($_SESSION['user'])) {
而不是,
if(!isset($_SESSION['user'])) {
希望这是问题。