I am having a problem creating a login page, i get the error "Notice: Undefined index: password2 in C:\Program Files\EasyPHP-5.3.8.1\www\Home (2).php on line 61" I have tried to fix it but i just cant see why its not working. I want to check the users from the table persons and the collumns are called "Email" and "password2"
<?php // Connects to your Database
mysql_connect("127.0.0.1", "root", "") or die ("Error , check your server connection.");
mysql_select_db("cocamp");
//Checks if there is a login cookie
if(isset($_COOKIE['ID_my_site']))
//if there is, it logs you in and directes you to the members page
{ $username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT Email FROM person WHERE Email = '$username'")or die(mysql_error());
while($person = mysql_fetch_array( $check )) { if ($pass != $person['password2']) { }
else { header("Location: members.php"); } } }
//if the login form is submitted
if (isset($_POST['submit'])) {
// if form has been submitted
// makes sure they filled it in
if(!$_POST['Email'] | !$_POST['password']) {
die('You did not fill in a required field.');
}
// checks it against the database
if (!get_magic_quotes_gpc()) {
$_POST['Email'] = addslashes($_POST['Email']);
}
$check = mysql_query("SELECT Email FROM person WHERE Email = '".$_POST['Email']."'")or die(mysql_error());
//Gives error if user dosen't exist
$check2 = mysql_num_rows($check);
if ($check2 == 0) {
die('That user does not exist in our database. <a href=add.php>Click Here to Register</a>');
}
while($person = mysql_fetch_array( $check ))
{
$_POST['password'] = stripslashes($_POST['password']);
$person['password2'] = stripslashes($person['password2']);
$_POST['password'] = md5($_POST['password']);
//gives error if the password is wrong
if ($_POST['password'] != $person['password2']) {
die('Incorrect password, please try again.');
}
else {
// if login is ok then we add a cookie
$_POST['Email'] = stripslashes($_POST['Email']); $hour = time() + 3600; setcookie(ID_my_site, $_POST['Email'], $hour); setcookie(Key_my_site, $_POST['password'], $hour);
//then redirect them to the members area
header("Location: members.php"); } } } else {
// if they are not logged in
?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table border="0"> <tr><td colspan=2><h1>Login</h1></td></tr> <tr>
<td>Username:</td><td> <input type="text" name="Email" maxlength="40"> </td></tr> <tr>
<td>Password:</td><td> <input type="password" name="password" maxlength="50"> </td></tr> <tr>
<td colspan="2" align="right"> <input type="submit" name="submit" value="Login"> </td></tr> </table> </form> <?php } ?>

New Topic/Question
Reply



MultiQuote





|