Page 1 of 1

[SOLVED] Problem in verify user password..

Posted: Mon May 24, 2004 10:09 pm
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?

Posted: Mon May 24, 2004 10:20 pm
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.
?>

Posted: Mon May 24, 2004 10:47 pm
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)

Posted: Mon May 24, 2004 11:04 pm
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.

Posted: Mon May 24, 2004 11:45 pm
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:

Posted: Tue May 25, 2004 3:38 pm
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>"; 

}    

?>

Posted: Tue May 25, 2004 4:31 pm
by Joe
Uh oh! Phenom fogot to put the error handles in again! HEHE!!!

Posted: Tue May 25, 2004 9:11 pm
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

Posted: Wed Jun 09, 2004 8:45 pm
by crypdude
Thanks dudes! Now I just have a new life... like live after dead...hehe!