phpacademy Forum

Watch, Listen, Learn!

login form doesnt seem to work [SOLVED]

For if you require help with PHP programming.

Re: login form doesnt seem to work

Postby aaronenabs » Fri Jul 30, 2010 2:12 am

thanks for that bit of help
i changed the places required and my code now looks like these:

Further more its got an error e-Parse error: syntax error, unexpected T_ELSE in checklogin.php on line 48
just to test it i have taken that bit out and same thing seems to happen from my login.php file when i enter a username and password it just takes me to blank page with /checklogin.php which is this page


  1.  
  2. <?php
  3.  
  4. session_start();
  5.  
  6. $username = $_POST['username'];
  7. $password = $_POST['password'];
  8.  
  9.  if (isset($_POST['submit']))
  10.  {
  11.  
  12.  if(empty($username) || empty($password))
  13.  {
  14.   die("Fill in all fields");
  15. }else {
  16.  
  17. $connect = mysql_connect("**","**","**") or die("Could not connect");
  18. mysql_select_db("uad0905525") or die ("could not connect");
  19.  
  20. $query = mysql_query("SELECT password FROM customer WHERE username='$username'");
  21.  
  22. $numrows = mysql_num_rows($query);
  23.  
  24. echo $numrows;
  25.  
  26. if ($numrows!=0)
  27. {
  28.  
  29.             $row = mysql_fetch_assoc($query);
  30.             $dbusername = $row['username'];
  31.             $dbpassword = $row['password'];
  32.    
  33.     if ($username==$dbusername&&$password==$dbpassword)
  34.     {
  35.         echo "Welcome, <a href='login_sucess.php'>Click</a> here to enter Website";
  36.         $_SESSION['username']=$username;
  37.     }
  38.     else
  39.     {
  40.         echo "Incorrect password";
  41.     }
  42.  
  43. }
  44. else
  45.     die ("That user doesn't exist!");
  46.  
  47.  
  48. }
  49. else     -----line 48
  50.     die ("Please enter username and password");
  51.  
  52.  }
  53. ?>
  54.  
  55.  
aaronenabs
 
Posts: 90
Joined: Tue Jul 27, 2010 4:34 pm
Online: 1d 3h 36m 49s
Karma: 0

Re: Re: login form doesnt seem to work

Advertisment

Advertisment
 

Re: login form doesnt seem to work

Postby Nero » Fri Jul 30, 2010 2:24 am

  1.  
  2. <?php
  3.  
  4. session_start();
  5.  
  6. $username = $_POST['username'];
  7. $password = $_POST['password'];
  8.  
  9.  if (isset($_POST['submit']))
  10.  {
  11.  
  12.  if(empty($username) || empty($password))
  13.  {
  14.   die("Fill in all fields");
  15. }else {
  16.  
  17. $connect = mysql_connect("**","**","**") or die("Could not connect");
  18. mysql_select_db("uad0905525") or die ("could not connect");
  19.  
  20. $query = mysql_query("SELECT password FROM customer WHERE username='$username'");
  21.  
  22. $numrows = mysql_num_rows($query);
  23.  
  24. echo $numrows;
  25.  
  26. if ($numrows!=0)
  27. {
  28.  
  29.             $row = mysql_fetch_assoc($query);
  30.             $dbusername = $row['username'];
  31.             $dbpassword = $row['password'];
  32.    
  33.     if ($username==$dbusername&&$password==$dbpassword)
  34.     {
  35.         echo "Welcome, <a href='login_sucess.php'>Click</a> here to enter Website";
  36.         $_SESSION['username']=$username;
  37.     }
  38.     else
  39.     {
  40.         echo "Incorrect password";
  41.     }
  42.  
  43. }
  44. else
  45.     die ("That user doesn't exist!");
  46.  
  47.  
  48. }
  49.  
  50.  }
  51. ?>
  52.  

I removed your die saying people to fill in fields as I've already added that before.
Image
Click "Give Karma" if my post was somewhat helpful.
Decreasing karma kills one cute kittehn

I would use an awesome signature image but it's over 90px high so no I can't...
User avatar
Nero
Top Contributor
 
Posts: 916
Joined: Tue Jun 23, 2009 7:54 am
Online: 7d 7h 46m 30s
Karma: 9

Re: login form doesnt seem to work

Postby wide_load » Fri Jul 30, 2010 2:26 am

that's normally a missing or extra curly bracket as well.

If you write the code neatly it becomes a bit more clear...

  1. <?php
  2.  
  3. session_start();
  4.  
  5. $username = $_POST['username'];
  6. $password = $_POST['password'];
  7.  
  8. if (isset($_POST['submit'])){
  9.     if(empty($username) || empty($password)){
  10.         die("Fill in all fields");
  11.     }else{
  12.         $connect = mysql_connect("**","**","**") or die("Could not connect");
  13.         mysql_select_db("uad0905525") or die ("could not connect");
  14.        
  15.         $query = mysql_query("SELECT password FROM customer WHERE username='$username'");
  16.          
  17.         $numrows = mysql_num_rows($query);
  18.          
  19.         echo $numrows;
  20.  
  21.         if ($numrows != 0){
  22.             $row = mysql_fetch_assoc($query);
  23.             $dbusername = $row['username'];
  24.             $dbpassword = $row['password'];
  25.    
  26.             if ($username == $dbusername && $password == $dbpassword){
  27.                 echo "Welcome, <a href='login_sucess.php'>Click</a> here to enter Website";
  28.                 $_SESSION['username'] = $username;
  29.             }else{
  30.                 echo "Incorrect password";
  31.             }
  32.         }else{
  33.             die ("That user doesn't exist!");
  34.         }
  35.     }
  36. else{
  37.     die ("Please enter username and password");
  38. }
  39.  
  40. ?>


see if you spot the missing bracket now

I have added curly brackets to all of the logic, even though they are not strictly necessary, it will make it lots easier to find missing ones if you follow one convention.

I also notice that you store the result of the mysql_connect function in a variable, and then never use it again.
Image
User avatar
wide_load
Top Contributor
 
Posts: 5375
Joined: Thu Aug 13, 2009 1:04 pm
Online: 12d 14h 21m 3s
Karma: 43

Re: login form doesnt seem to work

Postby Nero » Fri Jul 30, 2010 2:45 am

They all match up!

Tell me where it's missing!
Am going fucking insane!

There is one missing for the isset but there is more!
Image
Click "Give Karma" if my post was somewhat helpful.
Decreasing karma kills one cute kittehn

I would use an awesome signature image but it's over 90px high so no I can't...
User avatar
Nero
Top Contributor
 
Posts: 916
Joined: Tue Jun 23, 2009 7:54 am
Online: 7d 7h 46m 30s
Karma: 9

Re: login form doesnt seem to work

Postby aaronenabs » Fri Jul 30, 2010 2:55 am

yeah i did thanks, it was on line 9 i had 1 more extra.
i took that out not signs of any errors

but i still dont get any details as soon as i enter a username and password
which i already have in my database
i have just recopied the code to show you what i have now,

i took out the last bit
else{
die ("Please enter username and password

and it just took me to my checklogin.php but nothing was displayed (my welcome screen) but once i put it back in entered correct un&pw and wrong un&pw it took me to the same saying please enter username and password

  1.  
  2.      <?php
  3.    
  4.     session_start();
  5.      
  6.     $username = $_POST['username'];
  7.     $password = $_POST['password'];
  8.      
  9.     if (isset($_POST['submit']))
  10.         if(empty($username) || empty($password)){
  11.            die("Fill in all fields");
  12.        }else{
  13.            $connect = mysql_connect("**", "**","**");
  14.            mysql_select_db("uad0905525") or die ("could not connect");
  15.          
  16.            $query = mysql_query("SELECT password FROM customer WHERE username='$username'");
  17.            
  18.            $numrows = mysql_num_rows($query);
  19.            
  20.            echo $numrows;
  21.    
  22.            if ($numrows != 0){
  23.                $row = mysql_fetch_assoc($query);
  24.                $dbusername = $row['username'];
  25.                $dbpassword = $row['password'];
  26.      
  27.                if ($username == $dbusername && $password == $dbpassword){
  28.                    echo "Welcome, <a href='login_sucess.php'>Click</a> here to enter Website";
  29.                    $_SESSION['username'] = $username;
  30.                }else{
  31.                    echo "Incorrect password";
  32.                }
  33.            }
  34.            else{
  35.                die ("That user doesn't exist!");
  36.            }
  37.        }
  38.       else{
  39.        die ("Please enter username and password");
  40.  }
  41.  
  42.    ?>
  43.  
  44.  
aaronenabs
 
Posts: 90
Joined: Tue Jul 27, 2010 4:34 pm
Online: 1d 3h 36m 49s
Karma: 0

Re: login form doesnt seem to work

Postby Nero » Fri Jul 30, 2010 3:05 am

Your code has a missing bracket.

Copy and paste this code
  1. <?php
  2.  
  3. session_start();
  4.  
  5. $username = $_POST['username'];
  6. $password = $_POST['password'];
  7.  
  8.  if (isset($_POST['submit']))
  9.  {
  10.  
  11.  if(empty($username) || empty($password))
  12.  {
  13.   die("Fill in all fields");
  14. }else {
  15.  
  16. $connect = mysql_connect("**","**","**") or die("Could not connect");
  17. mysql_select_db("uad0905525") or die ("could not connect");
  18.  
  19. $query = mysql_query("SELECT password FROM customer WHERE username='$username'");
  20.  
  21. $numrows = mysql_num_rows($query);
  22.  
  23. echo $numrows;
  24.  
  25. if ($numrows!=0)
  26. {
  27.  
  28.             $row = mysql_fetch_assoc($query);
  29.             $dbusername = $row['username'];
  30.             $dbpassword = $row['password'];
  31.    
  32.     if ($username==$dbusername&&$password==$dbpassword)
  33.     {
  34.         echo "Welcome, <a href='login_sucess.php'>Click</a> here to enter Website";
  35.         $_SESSION['username']=$username;
  36.     }
  37.     else
  38.     {
  39.         echo "Incorrect password";
  40.     }
  41.  
  42. }
  43. else
  44.     die ("That user doesn't exist!");
  45.  
  46.  
  47. }
  48.  
  49.  }
  50. ?>
Image
Click "Give Karma" if my post was somewhat helpful.
Decreasing karma kills one cute kittehn

I would use an awesome signature image but it's over 90px high so no I can't...
User avatar
Nero
Top Contributor
 
Posts: 916
Joined: Tue Jun 23, 2009 7:54 am
Online: 7d 7h 46m 30s
Karma: 9

Re: login form doesnt seem to work

Postby aaronenabs » Fri Jul 30, 2010 3:16 am

nero

i basically just copied and pasted the code but still same problem
i think am joining you in going insane.
Someone please help

i just keep getting through to the checklogin page when i try to login which is just a simple php with a form and username password and submit button
i dont know if its the login.php file causing these as it just a simple php file
aaronenabs
 
Posts: 90
Joined: Tue Jul 27, 2010 4:34 pm
Online: 1d 3h 36m 49s
Karma: 0

Re: login form doesnt seem to work

Postby aaronenabs » Fri Jul 30, 2010 10:26 am

hi guys Please am still trying to find out why code to login isnt working
any suggestions. i have just downloaded a localhost server changed my details to localhost and exactly the same error message
aaronenabs
 
Posts: 90
Joined: Tue Jul 27, 2010 4:34 pm
Online: 1d 3h 36m 49s
Karma: 0

Re: login form doesnt seem to work

Postby wide_load » Fri Jul 30, 2010 11:06 am

from my post above, the missing } is form the start of line 36.

I really thought you would spot that :lol:
Image
User avatar
wide_load
Top Contributor
 
Posts: 5375
Joined: Thu Aug 13, 2009 1:04 pm
Online: 12d 14h 21m 3s
Karma: 43

Re: login form doesnt seem to work

Postby Nero » Fri Jul 30, 2010 3:32 pm

aaronenabs wrote:nero

i basically just copied and pasted the code but still same problem


Works for me, I think...Unless I gave you the wrong code...

Thank you wide_load...
I barrely got any sleep... :|
Image
Click "Give Karma" if my post was somewhat helpful.
Decreasing karma kills one cute kittehn

I would use an awesome signature image but it's over 90px high so no I can't...
User avatar
Nero
Top Contributor
 
Posts: 916
Joined: Tue Jun 23, 2009 7:54 am
Online: 7d 7h 46m 30s
Karma: 9

Previous

Return to PHP Help

Who's online?

Users browsing this forum: No registered users and 1 guest