I have created a test login page so that once a user logs in with correct credentials he/she should be directed to the main page.
The log in page is at: www.studykitchen.com/login.php
The main page page is at: www.studykitchen.com/main.php
I am collecting the data from the log in page and processing it in authenticate page with the following code: www.studykitchen.com/authenticate.php
The code is executing without any errors and I am getting the message, "Log in successful" but it is not redirecting to the main page. I have highlighted the line that I think is responsible for this malfunction. Please help.
The code that I am using is:
?>
The log in page is at: www.studykitchen.com/login.php
The main page page is at: www.studykitchen.com/main.php
I am collecting the data from the log in page and processing it in authenticate page with the following code: www.studykitchen.com/authenticate.php
The code is executing without any errors and I am getting the message, "Log in successful" but it is not redirecting to the main page. I have highlighted the line that I think is responsible for this malfunction. Please help.
The code that I am using is:
<?php
foreach
($_POSTas$key=>$value){
if
($key!="submit"){
$value
=htmlentities(stripslashes(strip_tags($value )));
echo
"\t<input type=\"hidden\" name=\"$key\" value=\"$value\">\n";
}
}
}
}
$errorMessage
= '';
if
(isset($_POST['Email']) && isset($_POST['Password'])) {
$db_host
= "localhost";
$db_user
= "XXXXX_YYYYY";
$db_password
= "AAAAAA";
$db_name
="BBBBB_CCCCC";
$db
= mysql_connect($db_host, $db_user, $db_password);
if
($db == FALSE){
$error
= "Could not connect to the Database Server. Please check user details. Error = ". mysql_error();
exit
($error);
}
}
echo
"Completed DB connection";
mysql_select_db($db_name, $db);
mysql_select_db($db_name, $db);
if
(!mysql_select_db($db_name, $db)) {
$error
= "Could not select Database. Please check user details. Error = ". mysql_error();
exit
($error);
}
}
echo
"Completed DB selection";
$userId = $_POST['Email'];
$password = $_POST['Password'];
// check if the user id and password combination exist in database
$userId = $_POST['Email'];
$password = $_POST['Password'];
// check if the user id and password combination exist in database
$sql = "SELECT Email
FROM UserDetails
WHERE Email = '$userId'
AND Password = '$password'";
$result = mysql_query($sql, $db);
if (mysql_num_rows($result) == 1) {
// the user id and password match,
FROM UserDetails
WHERE Email = '$userId'
AND Password = '$password'";
$result = mysql_query($sql, $db);
if (mysql_num_rows($result) == 1) {
// the user id and password match,
// set the session
$_SESSION['db_is_logged_in'] = true;
echo
"Log in successful";
// after login we move to the main page
// after login we move to the main page
header(
"Location: http://www.studykitchen.com/main.php");
exit;
} else {
$errorMessage = 'Sorry, wrong user id / password';
}
mysql_close($db);
}
exit;
} else {
$errorMessage = 'Sorry, wrong user id / password';
}
mysql_close($db);
}
?>
Comment