Connecting Tech Pros Worldwide Help | Site Map

login form does not output error messages

Newbie
 
Join Date: Aug 2007
Posts: 2
#1: Aug 23 '07
I have some problem this code. plz check and correct this code. My problem is If write wrong user id and password automatically enter my url not show the error message invalid user id or password.plz solve my problem early send my email full code using this database.

this is login page code login.php
Expand|Select|Wrap|Line Numbers
  1.  //Database Information
  2.  
  3. $dbhost = "localhost";
  4. $dbname = "_MUNGED_";
  5. $dbuser = "_MUNGED_";
  6. $dbpass = "_MUNGED_";
  7.  
  8. //Connect to database
  9.  
  10. mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
  11. mysql_select_db($dbname) or die(mysql_error());
  12.  
  13. session_start();
  14. $username = $_POST[‘username’];
  15. $password = md5($_POST[‘password’]);
  16.  
  17. $query = “select * from users where username=’$username’ and password=’$password’”;
  18.  
  19. $result = mysql_query($query);
  20.  
  21. if (mysql_num_rows($result) = 0) {
  22. $error = “Bad Login”;
  23.     include “login.html”;
  24.  
  25. } else {
  26.     $_SESSION[‘username’] = “$username”;
  27.     include “memberspage.php”;
  28. }
  29.  
  30. ?>
ak1dnar's Avatar
Moderator
 
Join Date: Jan 2007
Location: Colombo
Posts: 1,439
#2: Aug 23 '07

re: login form does not output error messages


Welcome to TSDN.

You have to echo the error messages.
Expand|Select|Wrap|Line Numbers
  1. echo $error;
pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#3: Aug 23 '07

re: login form does not output error messages


Heya, DeepG. Welcome to TSDN!

Changed thread title to better describe the problem (did you know that threads whose titles contain phrases such as, 'problem' actually get FEWER responses?).

I went ahead and removed the database login info from your post for your protection.

TSDN members are expected to write their own code. We're happy to help you out if you have specific questions, but you can't realistically expect someone to do your coding for you on a free forum.

Good idea to put your content on a separate page from the backend. Since you're already doing that, consider using header() redirection instead of include() so as to get rid of the annoying "Are you sure you want to resubmit POST data?" browser warning when the User refreshes the page or presses the back button.
Reply