We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

simplest way

locke2005
locke2005 asked
on
Medium Priority
278 Views
Last Modified: 2013-12-12
My code looks for all emails to see if $email is already in the database (that is right, because more than one user CAN NOT have the same email).

My code looks for all passwords to see if $password is already in the database (that is wrong, because more than one user CAN have the same password).


$password=mysql_real_escape_string($_POST['password']);

$select="SELECT * FROM area WHERE password LIKE '$password' LIMIT 1";

$password_select=mysql_query($select);


if(mysql_num_rows($password_select))
 {
  echo "The password is correct!";
 }
else
 {
  $error.=4;

  echo "The password is incorrect!";
 };


What is the simplest way to solve this problem?
Comment
Watch Question

This code is only checking to see if the password exists in the table.

It looks like code from a login script... Can you post your full code and explain your problem in a little more detail?
Is this code for logging a user in? Try this:

<?
$email=mysql_real_escape_string($_POST['email');
$password=mysql_real_escape_string($_POST['password']);
$select="SELECT * FROM area WHERE email = '$email' AND password = '$password'";

$password_select=mysql_query($select);


if(mysql_num_rows($password_select) == 1)
 {
  echo "The password is correct!";
 }
else
 {
  $error.=4;

  echo "The password is incorrect!";
 };
?>

This checks the password, for the supplied email address, and if exactly one row was returned, the password and email address provided are correct.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thank you, DrNikkon! You renewed my hope of working with MySQL!!!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.