soos Posted January 31, 2012 Share Posted January 31, 2012 Hey guys, I have an issue with my php code. After registering in my site, i (the user) can't login again. It displays a message: The email and password combination you entered is incorrect. <?php if(logged_in()) { $user_data = user_data('name'); echo 'Welcome, ', $user_data['name']; } else { ?> <form action="" method="post" > <p> Email: <input type="email" name="login_email" /> Password: <input type="password" name="login_password" /> <input type="submit" value="Log in" /> </p> </form> <?php } if (isset($_POST['login_email'], $_POST['login_password'])) { $login_email = $_POST['login_email']; $login_password = $_POST['login_password']; $errors = array(); if(empty($login_email) || empty($login_password)){ $errors[] = 'Email and password are required!'; } else { $login = login_check($login_email, $login_password); if($login === false) { $errors[] = 'The email and password combination you entered is incorrect.'; } } if(!empty($errors)) { foreach ($errors as $error) { echo $error. '<br />'; } } else { $_SESSION['user_id'] = $login; header('Location: index.php'); exit(); } } ?> And here's the function where I call check the login: <?php function login_check($email, $password) { $email = mysql_escape_string($email); $login_query = mysql_query("SELECT COUNT(`user_id`) as `count`, `user_id` FROM `users` WHERE `email`='$email' AND `password`='".md5($password) ."'"); return(mysql_result($login_query, 0) == 1) ? mysql_result($login_query, 0, 'user_id') : false; echo mysql_error(); } ?> Any clue of what this could be? Quote Link to comment Share on other sites More sharing options...
digibucc Posted January 31, 2012 Share Posted January 31, 2012 where's the registration page where the password is created/inserted? you've got to compare what gets inserted with the query results, and obviously what you are typing. Quote Link to comment Share on other sites More sharing options...
soos Posted January 31, 2012 Author Share Posted January 31, 2012 Here it is: <?php include 'init.php'; if(logged_in()) { header('Location: index.php'); exit(); } include 'template/header.php'; ?> <h3>Create your FREE account</h3> <?php if(isset($_POST['register_name'], $_POST['register_email'], $_POST['register_password'], $_POST['register_location'], $_POST['confirm_password'])) { $register_name = $_POST['register_name']; $register_email = $_POST['register_email']; $register_password = $_POST['register_password']; $confirm_password = $_POST['confirm_password']; $register_location = $_POST['register_location']; $register_category = $_POST['register_category']; $errors = array(); if(empty($register_name) || empty($register_email) || empty($register_password) || empty($confirm_password) || empty($register_location)) { $errors[] = '*All fields are required!'; } else { if(filter_var($register_email, FILTER_VALIDATE_EMAIL) === false) { $errors[] = 'The email address you entered is not valid'; } if($register_password != $confirm_password) { $errors[] = '*The passwords you entered do not match!'; } if(strlen($register_email) > 255 || strlen($register_name) > 35 || strlen($register_password) > 32 || strlen($register_location) > 35) { $errors[] = '*One or more fields contain too many characters'; } if(user_exists($register_email) === true) { $errors[] = '*The email address you entered already exists!'; } } if(!empty($errors)) { foreach($errors as $error){ echo $error . '<br />'; } } else { $register = user_register($register_id, $register_name, $register_email, $register_password, $register_location, $register_category); $_SESSION['user_id'] = $register; echo $_SESSION['user_id']; header('Location: index.php'); exit(); } } ?> <form action="" method="post"> <p>Name: <br><input type="text" name="register_name" size="46" maxlength="35" /></p> <p>Email: <br><input type="email" name="register_email" size="46" maxlength="255" /></p> <p>Password: <br><input type="password" name="register_password" size="46" maxlength="40" /> </p> <p>Re-type password: <br><input type="password" name="confirm_password" size="46" maxlength="40" /></p> <p>Location: <br><input type="text" name="register_location" size="46" maxlength="35" /></p> <p>I am a: <select name="register_category" > <option value="Home buyer">Home buyer</option> <option value="Home seller">Home seller</option> <option value="Renter">Renter</option> <option value="Real Estate Professional">Real Estate Professional</option> <option value="Other">Other</option> </select> </p> <p><br><input type="submit" value="register"/></p> </form> <?php include 'template/footer.php'; Quote Link to comment Share on other sites More sharing options...
soos Posted January 31, 2012 Author Share Posted January 31, 2012 Disregard this post. I figured out the issue. Thanks anyway. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.