log in
Posted: Sun Apr 03, 2011 1:20 pm
Hi...I've been trying to make my log-in script work out for like...two hours.It says - - - Notice: Undefined variable: username in C:\xampp\htdocs\manage\login_form.php on line 65 ---- when I try to log in. I still can't figure out what I'm doing wrong ,although I'm sure I've made some stupid mistake. I'll be really happy if somebody can help me with that
.Here's the code :
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title></title>
</head>
<body>
<?php
$connect = mysql_connect("localhost", "root", "0000") or die(mysql_error());
mysql_select_db("manage_books") or die(mysql_error());
if (((isset($_POST['submit']) &&
($_POST['username'] == null) &&
($_POST['pass'] == null))) |
(!isset($_POST['submit']) &&
(!isset($_POST['username'])) &&
(!isset($_POST['pass']))))
{
?>
<center>
<form action='' method='post'>
<br><br><br><br><br>
<b>USERNAME</b>:<input type='text' name='username' maxlength='30' size='15'><br>
<?php
if (!isset($_POST['username']) && isset($_POST['submit'])) {
echo"A username is required.<br>";
} else
?>
<b>PASSWORD</b>:<input type='password' name='pass' maxlength='30' size='17'><br>
<?php
if (!isset($_POST['pass']) && isset($_POST['submit'])) {
echo"A password is required.<br>";
}
?>
<input type='submit' name='submit' value='Log In'>
</form></center>
<?php
}
else {
if(get_magic_quotes_gpc()) {
$username = stripslashes($_POST['username']);
$password = stripslashes($_POST['pass']);
}
$username1 = mysql_real_escape_string($username);
$sql = "SELECT pass,id FROM users WHERE user='" . $username1 . "'";
$res = mysql_query($sql);
if ($res) {
$row = mysql_fetch_assoc($res);
$pass = $row['pass'];
if (md5($_POST['pass']) != $pass) {
die("Incorrect password");
}
else {
$_SESSION['user'] = $username1;
$_SESSION['id'] = $row['id'];
header("location:pagination.php");
}
} else {
exit;
}
}
?>
</body>
</html>