just having an issue with an index error. It's basically throwing this at me
http://puu.sh/chc2e/7e26d51bda.png
I am unsure of why it's giving it to me as I have listed it in the index? Any ideas
My code:
<?php
include ('config.php');
?>
<?php
// Getting username and password from login form
$username = $_POST['username'];
$password = md5($_POST['password']);
// To protect MySQL injection
$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
$sql="SELECT * FROM login WHERE username='$username' and password='$password'";
$result=mysql_query($sql);
// Mysql_num_row is to count number of row from the above query
$count=mysql_num_rows($result);
// count is 1 if the above username and password matches
if($count==1){
// now redirect to dashboard page, we also store the username in session for further use in dashboard
$_SESSION['username']= $username; // storing username in session
header("location:index.php");
}
//if the username and password doesn't match redirect to homepage with message=1
else {
echo '
<script language="javascript" type="text/javascript">
window.location.href="index.php?message=1";
</script>';
}
?>
Any help is appreciated. Thanks!
EDIT: User asked to see my Login form
<?php
if(isset($_POST["submit"])){
if(!empty($_POST['user']) && !empty($_POST['pass'])) {
$user=$_POST['user'];
$pass=$_POST['pass'];
$pass = strip_tags($pass);
$pass = md5($pass); // md5 is used to encrypt your password to make it more secure.
$con=mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('aha') or die("cannot select DB");
$query=mysql_query("SELECT * FROM login WHERE username='".$user."' AND password='".$pass."'");
$numrows=mysql_num_rows($query);
if($numrows!=0)
{
while($row=mysql_fetch_assoc($query))
{
$dbusername=$row['username'];
$dbpassword=$row['password'];
}
if($user == $dbusername && $pass == $dbpassword)
{
session_start();
$_SESSION['sess_user']=$user;
/* Redirect browser */
header("Location: member.php");
}
} else {
echo "<div class='results'>Invalid username or password</div>";
}
} else {
echo "All fields are required!";
}
}
?>
HTML LOGIN:
<form action="" method="POST">
<label>Username:</label>
<input type="text" name="user" required />
<label>Password:</label>
<input type="password" name="pass" required />
<input type="submit" value="Login" name="submit" class="submit" />
<br><br>
<center>
<h2><p><a href="register.php">Register</a></p></h2>
</center>