2

Does anyone know whats wrong with this?, the else is echo'd even if credentials are correct

include("includes/dbconn.php");
// username and password sent from form 
$username=$_POST['username']; 
$password=$_POST['password']; 

$sql=("SELECT * FROM customers WHERE email ='.$username.' and password='.$password.'");
$result=mysql_query($sql);
$count=mysql_num_rows($result);

if($count==1){

    session_register("username");
    session_register("password"); 
    header("location:login_success.php");

} else {
    echo "Wrong Username or Password";
}
2
  • 1
    Please stop storing plain text passwords also this query is completely open to attack. Commented Sep 24, 2014 at 4:51
  • can u post ur dbconn.php file??? Commented Sep 24, 2014 at 4:59

1 Answer 1

2

The else section is executing because your query had failed. Remove the unnecessary brackets from the query. Also you are appending the values incorrectly. As you are enclosing the query within brackets, there is no need of appending it again.

So change your query

$sql=("SELECT * FROM customers WHERE email ='.$username.' and password='.$password.'");

to

$sql="SELECT * FROM customers WHERE email ='$username' and password='$password'";
Sign up to request clarification or add additional context in comments.

8 Comments

theses are the least of the problems here
please don't this is the worst approach to take
@Dagon what do you mean?
plain text password no user variable sanitation - its security 101
@Dagon i got your point brother, but this post solved the problem. So this deserves a upvote. Also now we can tell Ellis how to implement security issues. :)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.