I am building a member site. I have created the following pages called login2.php (second iteration), profile.php, and sign-up.html. I also have a MySQL database up and running. When I login with a username and password in my database I am redirected to sign-up.html instead of profile.php like I'm intending. Here is the code for login2.php:
$uname= "";
$pword= "";
$errorMessage = "";
function quote_smart($value, $handle) {
if (get_magic_quotes_gpc()) {
$value = stripslashes($value);
}
if (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value, $handle) . "'";
}
return $value;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST'){
$uname = $_POST['userName'];
$pword = $_POST['pass'];
$uname = htmlspecialchars($uname);
$pword = htmlspecialchars($pword);
// CONNECT TO THE LOCAL DATABASE
$host = "localhost";
$username = "root";
$password = "******";
$db = "*******";
$db_handle = mysql_connect($host, $username, $password);
$db_found = mysql_select_db($db, $db_handle);
if ($db_found) {
$uname = quote_smart($uname, $db_handle);
$pword = quote_smart($pword, $db_handle);
$SQL = "SELECT * FROM WebsiteUsers WHERE userName = $uname AND pass = md5($pword)";
$result = mysql_query($SQL);
$num_rows = mysql_num_rows($result);
// CHECK TO SEE IF THE $result VARIABLE IS TRUE
if ($result) {
if ($num_rows > 0) {
session_start();
$_SESSION['login'] = "1";
header ("Location: profile.php");
}
else {
session_start();
$_SESSION['login'] = "";
header ("Location: sign-up.html");
}
}
else {
$errorMessage = "Error logging on";
}
mysql_close($db_handle);
}
else {
$errorMessage = "Error logging on";
}
}
?>
<html lang="en">
<head>
<title>yoointoo | login</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.2-dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.2-dist/css/main.css">
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.2-dist/css/login.css">
</head>
<body>
<br><br><br><br>
<div class="container">
<div class="row">
<div class="col-md-offset-4 col-md-5">
<div class="form-login">
<h1>yoointoo</h1>
<h4>Welcome back!</h4>
<form method="POST" action="login2.php">
<input type="text" name="user" class="form-control input-sm chat-input" value="<?PHP print $uname;?>" placeholder="username" />
</br>
<input type="password" name="pass" id="userPassword" value="<?PHP print $pword;?>" class="form-control input-sm chat-input" placeholder="password" />
</br>
<input id="button" class="btn btn-primary btn-md" type="submit" name="submit" value="Login">
</form>
<p><?PHP print $errorMessage;?>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
The code for profile.php looks like this:
<?php
session_start();
if (!(isset($_SESSION['login']) && $_SESSION['login'] != '')) {
header ("Location: login2.php");
}
?>
This is just the php at the top before all of my html.
The code for sign-up.html is just html no php that would be affecting anything. And finally these are the fields for the MySQL table:
email fullname pass userID userName
Any ideas why after a successful login I am being redirected to sign-up.html instead of profile.php?
Thanks!