[SOLVED] Problem in verify user password..

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
crypdude
Forum Newbie
Posts: 18
Joined: Sun May 23, 2004 10:26 pm

[SOLVED] Problem in verify user password..

Post by crypdude »

This is my code

Code: Select all

<?php
  $query = "SELECT * FROM register_user where user_id= '$id' AND password='$pwd'";
   $result = mysql_query($query);
   $query_data = mysql_fetch_row($result);
      IF (!$query_data[0]) {
	  echo("<center><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>");
      $error = "You have submited an incorrect login and password combination.  Please try again!";
	  echo($error);
	  echo("&nbsp;<a href="index.php">login user</a></center>");
      }
   ELSE{
	   echo($query);
	   $user= $query_data["user_type"];
	   $user_id= $query_data["user_id"];
	   echo("$user_id");
	   if ($user == "Data Entry")
	   {
		   echo("<br>U are ");
		   echo("$user!");
	   }
	   else
	   {
		   echo("<br>U are ");
		   echo("suppose to be not data entry!");
		   echo("U are ");
		   echo("$user!"); 
?>
Actually, there are many users will use my system, then when i select it by using their id and password, then system will know the type of user who currently try to access my system. I try to do my best, but not working. Can anyone help me?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

<?php

  $result = @mysql_query("SELECT * FROM register_user where user_id= '$id' AND password='$pwd'"); 
  $numrow = mysq_num_rows($result);

if ($numrows > 0){

      // succesful login

      if ($user == "Data Entry") 
      { 
         echo "<br>You are ".$user."!";
      } 
      else 
      { 
         echo "<br>You are not Data Entry, you are ".$user;
      }

}else{
 
     // unsuccesful login
 
    echo "You have submited an incorrect login and password combination.  Please try again!";
    echo "<center><a href='index.php'>login user</a></center>"; 

}   
?>
This should work and is alot more clean.
?>
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Yup go with Phenoms method. Can i note

$result = @mysql_query("SELECT * FROM register_user where user_id= '$id' AND password='$pwd'");
$numrow = mysq_num_rows($result);

SHOULD BE:

$result = @mysql_query("SELECT * FROM register_user where user_id= '$id' AND password='$pwd'") or die("Query Error!");
$numrow = mysq_num_rows($result);

always best to check errors in the scripts and querys, lol


Joe 8)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Silly me, how did I miss that... you should always have an escape to report your errors.. sometimes they don't all get shown ( unless you got error_reporting(E_ALL) on.
User avatar
crypdude
Forum Newbie
Posts: 18
Joined: Sun May 23, 2004 10:26 pm

Post by crypdude »

Thanks for all favours!

But when i trying to do so, I can't access it anymore.. It seem like can't get $numrow..even do i change it from

Code: Select all

<?php
$numrow = mysq_num_rows($result)
?>
to

Code: Select all

<?php
$numrow = mysql_num_rows($result)
?>
..

That is not my currently actual problem, my problem is how to get data from ($user) and how to check it either it is Data Entry or not? How to get it($user) from the sql query? Pls help me..!!!

May God bless! :idea:
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

K here is what I got from that: I still don't know what user is. Is it the users name? or is it they level level? what? I ask this because I have no idea what $dataentry is supposed to mean. And thirdly I'm assuming you are pulling dataentry from the database.

Code: Select all

<?php
<?php 

  $result = @mysql_query("SELECT * FROM register_user where user_id= '$id' AND password='$pwd'"); 
  $numrow = @mysq_num_rows($result); 

if ($numrows > 0){ 
  $row = @mysql_fetch_array($result))      
  $user= $row["user"];

      // succesful login 

      if ($user == "Data Entry") 
      { 
         echo "<br>You are ".$user."!"; 
      } 
      else 
      { 
         echo "<br>You are not Data Entry, you are ".$user; 
      } 

}else{ 

     // unsuccesful login 

    echo "You have submited an incorrect login and password combination.  Please try again!"; 
    echo "<center><a href='index.php'>login user</a></center>"; 

}    

?>
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Uh oh! Phenom fogot to put the error handles in again! HEHE!!!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

hehe sorry i just used edit from my last post..

dont forget to add in your error reporting.
or else. <--- my php joke!!

HAHAH LAUGH
User avatar
crypdude
Forum Newbie
Posts: 18
Joined: Sun May 23, 2004 10:26 pm

Post by crypdude »

Thanks dudes! Now I just have a new life... like live after dead...hehe!
Post Reply