Page 1 of 1

Please help

Posted: Wed Sep 11, 2013 6:57 am
by xbear1982
Hi There
I am a beginner of php, tried learn php through practise.
I did some code for login scrip, but how ever it see to be do not work. please help.

for log in html page

Code: Select all

<html>

      <head> 

            <title>Login Form</title> 

      </head> 

      <body> 

            <form action='checklogin.php' method='post'> 

                  Username : <input type='text' name='username'> <br/> 

                  Password : <input type='text' name='password'> <br/> 

                                       <input type='submit' value='Login'> 

            </form> 

</body> 

</html>

for checklogin.php

Code: Select all

<?php

   //connecting to database

   $db = mysql_connect("localhost","root","01959719") or die(mysql_error());

 

   //selecting our database

 $db_select =mysql_select_db("customer", $db);

 

   //Retrieving data from html form

   $username = '$_POST[username]';

   $password = '$_POST[Password]';

 

   //for mysql injection (security reasons)

   $username = mysql_real_escape_string($username);

  $password = mysql_real_escape_string($password);

 

   //checking if such data exist in our database and display result

   $members = mysql_query("select * from members where USERNAME = '$username' and

   Password = '$password'");

   if(mysql_num_rows($members) == 1) 
   {

      echo "Login Successfull";
	  

   }

   else {

      echo "Username and Password does not Match";

   }

?>
after I tried it out it see to be not working only appear "Username and Password does not Match".

Pleae help!!!! :banghead:

Re: Please help

Posted: Wed Sep 11, 2013 7:04 am
by Celauran
It's generally a good idea to store your query in a separate variable so you can echo exactly what's being passed to MySQL. Also, have you checked how many rows are being returned?

Re: Please help

Posted: Wed Oct 23, 2013 4:49 am
by xbear1982
thanks for your advise
I was tried it to run the code above
it went to
it run ok
till
I place echo "hello";
before
"if(mysql_num_rows($members) == 1)
{

echo "Login Successfull";


}

" then it did not return.

but I am unable to figure out what is missing, please advise.