when I hit login it keeps saying invalid login information. I want it to go to profile.php
I used header('location:profile.php')
I wonder whats wrong? may you guys take a look please, and let me know if I'm missing something or had typos. thanks!
<?php
//database information
$host = "localhost";
$user = "root";
$pass = "";
$db = "test";
//connect to database
mysql_connect($host, $user, $pass);
mysql_select_db($db);
//select table
$sql = "SELECT * FROM users WHERE username='".$username."' AND password='".$password."' LIMIT 1";
$res = mysql_query($sql);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Admin Login</title>
<link href="../sources/stylesheet.css" rel="stylesheet" type="text/css" />
</head><body>
<div id="content_login">
<div id="header">
<p align="center"><u>NJROTC ADMINS</u></p>
<div id="Quote">
<p align="center">You cannot be on this page if you weren't given the login information! </p>
</div>
</div>
<p> </p>
<p><br />
</p>
<form id="form1" name="form1" method="post" action="/njrotc/pages/login.php">
<table width="331" height="141" border="0">
<tr>
<td width="112">Username</td>
<td width="178"><input type="text" name="username" id="text2" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" id="password" /></td>
</tr>
<tr>
<td colspan="2"><div class="php">
<?php
if (isset($_POST['username'])) {
$username = $_POST['username'];
$password = $_POST['password'];
if (mysql_num_rows($res) == 1) {
echo "You have successfully logged in.";
exit();
} else {
echo "Invalid log in information.";
exit();
header ('location:profile.php');
}
}
?>
</div></td>
</tr>
<tr>
<td><input type="submit" name="submit" id="submit" value="Log In" /></td>
<td> </td>
</tr>
</table>
</form>
</div>
</body>
</html>