help please login problem this time

Thread Solved

Join Date: Apr 2008
Posts: 75
Reputation: mustafaneguib is an unknown quantity at this point 
Solved Threads: 3
mustafaneguib mustafaneguib is offline Offline
Junior Poster in Training

help please login problem this time

 
0
  #1
Jun 21st, 2008
help please once again... my login page was working just fine when one morning it just stopped to function. now i have tried to fix it, buy changing some of the logic and also recreating the database.

now the point i have reached is that when the user enters his correct user name and correct password , the user is allowed access, but if the user gives a totally wrong username and password the access is denied. the problem now comes. when the user enters the correct user name but the wrong password he still is granted access. now i cant fix this problem.

by being granted access i mean the word hello is displayed, and by not allowed i mean the word no is displayed.

this happens when i replace
  1. include 'config.php';
  2. $connect=mysql_connect($hostname, $username, $password);
  3.  
  4. with
  5.  
  6. $connect=mysql_connect(hostnamevalue, usernamevalue, passwordvalue);
but if use the former one the user does not login at all. is the problem that i have used the session names and also the config.php variables of the same names, but i changed them and tried i couldnt login at all.
  1.  
  2.  
  3. <?php
  4.  
  5. session_start();
  6. $_SESSION['username']=$_POST['user'];
  7. $_SESSION['password']=$_POST['pass'];
  8. $_SESSION['authuser1']=0;
  9.  
  10.  
  11. include 'config.php';
  12. $connect=mysql_connect($hostname, $username, $password);
  13.  
  14. mysql_select_db("worldofp_blog1")
  15. or die(mysql_error());
  16.  
  17.  
  18.  
  19. $get="SELECT user_name, pass_word
  20. From user
  21. WHERE user_name = '" . $_SESSION['username'] . "'
  22. ORDER BY user_name";
  23.  
  24. $results=mysql_query($get)
  25. or die(mysql_error());
  26.  
  27.  
  28.  
  29. $get1="SELECT user_name, pass_word
  30. From user
  31. WHERE pass_word = '" . $_SESSION['password'] . "'
  32. ORDER BY user_name";
  33.  
  34. $result=mysql_query($get1)
  35. or die(mysql_error());
  36.  
  37.  
  38. $row=mysql_fetch_array($results, $result);
  39.  
  40.  
  41. $authuser= $row['user_name'];
  42. $authpass= $row['pass_word'];
  43.  
  44. if($authuser and $authpass)
  45. {
  46.  
  47. echo "hello";
  48. $_SESSION['authuser1']==1;
  49. }
  50. else
  51. {
  52. echo "no";
  53. $_SESSION['authuser1']==0;
  54. }
  55.  
  56.  
  57.  
  58. ?>
Last edited by mustafaneguib; Jun 21st, 2008 at 8:09 am.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,747
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: help please login problem this time

 
0
  #2
Jun 21st, 2008
Few questions..
1. Why are you using sessions before authenticating the user ?
2. Why are you having 2 different queries for checking a valid user ?
3. order by user_name ? You don't need that actually !
And mysql_fetch_array's syntax is
mysql_fetch_array(result, result_type);
result_type = MYSQL_ASSOC or MYSQL_NUM.
$_SESSION['authuser1']==1;
== is a comparison operator, you should use = .
Isn't this a complete reduced version of your code ?
  1. <?php
  2. session_start();
  3.  
  4. include 'config.php'; //contains $hostname,$username,$password
  5.  
  6. $connect=mysql_connect($hostname, $username, $password); //connect
  7. mysql_select_db("worldofp_blog1") or die(mysql_error()); //select db
  8.  
  9. /* sanitize user's input */
  10. $user = mysql_real_escape_string($_POST['user']);
  11. $pass = mysql_real_escape_string($_POST['pass']);
  12.  
  13.  
  14. $get="SELECT user_name, pass_word from user where user_name='$user' and pass_word='$pass'"; //check if username and password exists
  15. $result=mysql_query($get) or die(mysql_error());
  16. $is_valid = mysql_num_rows ($result);
  17.  
  18. if($is_valid) { // if a record exist set $_SESSION['authuser1'] = 1
  19. echo "hello";
  20. $_SESSION['authuser1']=1;
  21. } else { //else set $_SESSION['authuser1'] = 0
  22. echo "no";
  23. $_SESSION['authuser1']=0;
  24. }
  25. ?>
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: mustafaneguib is an unknown quantity at this point 
Solved Threads: 3
mustafaneguib mustafaneguib is offline Offline
Junior Poster in Training

Re: help please login problem this time

 
0
  #3
Jun 21st, 2008
thanks, alot. im actually more of a c++ programmer than a php programmer as ive done that in the uni. also this is my first php attempt so i dont know much about the rules of the php.

the two equals signs much have been left there by accident because i was copying and pasting the code from one area of my code to the other.
Last edited by mustafaneguib; Jun 21st, 2008 at 12:43 pm.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,747
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: help please login problem this time

 
0
  #4
Jun 21st, 2008
ah! I see.. So, did it fix the problem or are you still facing some kinda problem ?
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: mustafaneguib is an unknown quantity at this point 
Solved Threads: 3
mustafaneguib mustafaneguib is offline Offline
Junior Poster in Training

Re: help please login problem this time

 
0
  #5
Jun 21st, 2008
Originally Posted by nav33n View Post
ah! I see.. So, did it fix the problem or are you still facing some kinda problem ?
that fixed it thanx again
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 3,747
Reputation: nav33n is a jewel in the rough nav33n is a jewel in the rough nav33n is a jewel in the rough 
Solved Threads: 331
Moderator
Featured Poster
nav33n's Avatar
nav33n nav33n is offline Offline
Senior Poster

Re: help please login problem this time

 
0
  #6
Jun 21st, 2008
you are welcome!
Ignorance is definitely not bliss!

*PM asking for help will be ignored*
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC