When the user correctly inserts his information in the login form it redirects to the home page which is what i want but i'm having a problem when the user inputs wrong info. It just shows connected successfully and database successfully selected. It stops on the page checklogin.php. As if it doesn't even read the session part. Please go through my code.
Here's my code for the register form:
<?php
$con=mysql_connect("localhost","root","");
if(!$con){
die('Could not connect:' .mysql_error());
}
echo "Connected successfully.";
$database=mysql_select_db('90210store');
if(!$database){
die('<br>Could not select database:' .mysql_error());
}
echo "<br>Database successfully selected";
$FirstName=$_POST['FirstName']; //to get the information written in the form
$LastName=$_POST['LastName'];
$EmailAdd=$_POST['EmailAdd'];
$check_list=$_POST['check_list'];
$dob=$_POST['dob'];
$Gender=$_POST['gender'];
$Password=$_POST['Password'];
$first= "INSERT INTO login
(FirstName,LastName,EmailAdd,Newsletter,DOB,Gender,Password)
VALUES
('$FirstName','$LastName','$EmailAdd','$check_list','$dob','$Gender','$Password')";
$result=mysql_query($first);
if($result){
echo('<br>Data enterred successfully');
}
else{
echo('<br>Fail');
}
if($result)
{
header('Location: phpredirectlogin.php');
}
mysql_close($con);
?>
Then this is the page it redirects to(phpredirectlogin.php):
<?php
echo "<script>alert('Redirecting you to the login page');</script>";
echo "<script>window.location = 'account.html';</script>";
?>
This is the php page which checks the login(checklogin.php):
<?php
$Email=$_POST['email'];
$Pwd=$_POST['pwd'];
$con=mysql_connect("localhost","root","");
if(!$con){
die('Could not connect:' .mysql_error());
}
echo "Connected successfully.";
$database=mysql_select_db('90210store');
if(!$database){
die('<br>Could not select database:' .mysql_error());
}
echo "<br>Database successfully selected";
$result = mysql_query("SELECT * FROM login
WHERE EmailAdd='$Email' AND Password='$Pwd'") or die('QueryFailed:'.mysql_error());
while($row=mysql_fetch_array($result))
{
session_start();
$_SESSION['ID']=1234;
header('Location:checklogin1.php');
}
mysql_close($con);
?>
Then this page redirects the user to checklogin1.php.The code is:
<?php
session_start();
if(!isset($_SESSION['ID']))
{
header('Location:account.html');
}
else
{
header('Location:90210.html');
}
?>
There has to be some error somewhere but i can't seem to figure it out. Any help will be appreciated. Thank you.