Jump to content

unable to login


nadeem14375

Recommended Posts

Dear all,

 

I am new to PHP. here I want to develop a login page. what's wrong in the following page?

 

<?php

include ('/includes/dbConfig.php');

session_start();

// username and password sent from form

$email=$_POST['email'];

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

 

// To protect MySQL injection (more detail about MySQL injection)

$email = mysql_real_escape_string($email);

$password = mysql_real_escape_string($password);

 

$query="SELECT * FROM member_info WHERE email='$email' and password='$password'";

 

$result=mysql_query($query);

 

if (mysql_num_rows($result) != 1) {

//$error = "Bad Login";

echo "Bad Login";

 

}

else

{

header("location:index.php");

}

?>

 

Regards:

Muhammad Nadeem

Link to comment
https://forums.phpfreaks.com/topic/240102-unable-to-login/
Share on other sites

yep. unless I'm missing something, code seems fine to me.

what exactly is the error? you just asked if there was anything wrong but you never told us what was happening when you try to login.

 

are you sure the stored passwords were also encrypted with md5() ? are you sure you're using the correct password?

 

set one of the passwords to 123, remove the md5() line and test again just to be sure.

 

Link to comment
https://forums.phpfreaks.com/topic/240102-unable-to-login/#findComment-1233312
Share on other sites

ok, try this:

remove and password='$password' from your $query

then go back to your original code and change this:

if (mysql_num_rows($result) != 1) {
//$error = "Bad Login";
echo "Bad Login";
}

 

for this:

 

if (mysql_num_rows($result) != 1) {
//$error = "Bad Login";
   echo "Bad Login: Cannot find that email";
}else{
   echo "Must be wrong password";
}

 

 

Also, keep in mind that mysql_num_rows($result) != 1 checks to see if the result is 1 row. If that emails exists more than once in the database this will also fail because num_rows will be 2 or more.

Hope this helps

Link to comment
https://forums.phpfreaks.com/topic/240102-unable-to-login/#findComment-1233336
Share on other sites

dear,

 

without md5, its ok.

but when i store in database with md5, the i couldn't be able to login, as i mentioned.

 

1. before insertion convert to md5(). the password is now encrypted.

 

2. login time , before selecting from database, md5().

or

only select from database. both don't let me to login.

 

What's the problem?

 

 

ok, try this:

remove and password='$password' from your $query

then go back to your original code and change this:

if (mysql_num_rows($result) != 1) {
//$error = "Bad Login";
echo "Bad Login";
}

 

for this:

 

if (mysql_num_rows($result) != 1) {
//$error = "Bad Login";
   echo "Bad Login: Cannot find that email";
}else{
   echo "Must be wrong password";
}

 

 

Also, keep in mind that mysql_num_rows($result) != 1 checks to see if the result is 1 row. If that emails exists more than once in the database this will also fail because num_rows will be 2 or more.

Hope this helps

Link to comment
https://forums.phpfreaks.com/topic/240102-unable-to-login/#findComment-1233703
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.