Please help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xbear1982
Forum Newbie
Posts: 9
Joined: Sun Aug 18, 2013 10:50 pm

Please help

Post 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:
Last edited by requinix on Wed Sep 11, 2013 1:20 pm, edited 2 times in total.
Reason: please use [syntax=php] tags when posting PHP code
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Please help

Post 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?
xbear1982
Forum Newbie
Posts: 9
Joined: Sun Aug 18, 2013 10:50 pm

Re: Please help

Post 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.
Post Reply