My code below doesn't go to if ( $loginsuccess == 1 )
. Everytime i try logging in it directs me to the else{
part of my code.
<?PHP
session_start();
$userid = $_POST['userid'];
$password = $_POST['password'];
$loginsuccess = 0;
$con = mysqli_connect('localhost', 'root');
if (!$con)
{
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con, 'btr');
$result = mysqli_query("SELECT * FROM user WHERE UserID='" . $userid . "'");
while($row = mysqli_fetch_array($result))
{
if ( $row['password'] == $password ){
$loginsuccess = 1;
}
}
mysqli_close($con);
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
<script src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>
<script type="text/javascript">
<!--
function redirect_index(){
window.location = "menu.php"
}
function redirect_login(){
window.location = "login.php"
}
//-->
</script>
<title>Test</title>
</head>
<body>
<?PHP
if ( $loginsuccess == 1 ){
$_SESSION['userid'] = $userid;
?>
<div data-role="page" class="login">
<script type="text/javascript">
$('.login').live("pagecreate", function() {
setTimeout("redirect_index();", 3000);
});
</script>
<div data-role="header">
<h1>
Test
</h1>
</div>
<div data-role="content">
Login successful. You will be redirected to main page in 3 seconds...<br />
<a href="menu.php">Back</a>
</div>
<div data-role="footer">
Test
</div>
</div>
<?PHP
} else{
unset($_SESSION['userid']);
?>
<div data-role="page" class="login">
<script type="text/javascript">
$('.login').live("pagecreate", function() {
setTimeout("redirect_login();", 3000);
});
</script>
<div data-role="header">
<h1>
Test
</h1>
</div>
<div data-role="content">
Invalid id or password. You will be redirected to login page in 3 seconds...<br />
<a href="login.php">Login</a>
</div>
<div data-role="footer">
Test
</div>
</div>
<?PHP
}
?>
</body>
</html>
could it be the data pass from the previous page ?
<?PHP
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.css" />
<script src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0a3/jquery.mobile-1.0a3.min.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=true" type="text/javascript"></script>
<script type="text/javascript">
<!--
function redirect_index(){
window.location = "menu.php"
}
function redirect_login(){
window.location = "login.php"
}
//-->
</script>
<title>/title>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>
Login
</h1>
</div>
<div data-role="content">
<form method="post" action="login_script.php">
<div data-role="fieldcontain">
<label for="userid">
ID
</label>
<input type="text" name="userid" id="userid" value=""/>
</div>
<div data-role="fieldcontain">
<label for="password">
Password
</label>
<input type="password" name="password" id="password" value=""/>
</div>
<input type="submit" value="Login" data-role="button" data-inline="true"/>
</form>
</div>
<div data-role="footer">
</div>
</div>
</body>
</html>