Jump to content

[SOLVED] check if user exists and if so get password


Bendude14

Recommended Posts

Ok im pretty new to MySql i dont want someone to just right this i would just like a few examples to set me of in the right direction.

 

I will be retrieving a username and password via POST and would like to first check if the username exists and if so then check it against the password.

 

I have a table called users and the different columns i have are user_id(primary key) username and password.

 

I am using mySql not Sqli as my host does not support this.

 

Thanks for the help

ok i have got this but it dont seem to work can anyone help thanks

 

  <?php    /* Verify that user is in database */
      $sql = "SELECT pwd FROM users WHERE username = '$username'";
      $result = mysql_query($sql) or die(mysql_error());
      if(!$result || (mysql_numrows($result) < 1)){
         return 1; //Indicates username failure
	 echo "incorrect username";
      }

      /* Retrieve password from result, strip slashes */
      $dbarray = mysql_fetch_array($result);
      $dbarray['pwd'] = stripslashes($dbarray['pwd']);
      $pwd = stripslashes($pwd);

      /* Validate that password is correct */
      if($pwd == $dbarray['pwd']){
         return 0; //Success! Username and password confirmed
	 echo "both correct";
      }
      else{
         return 2; //Indicates password failure
	 echo "incorrect password";
      }?>

 

All i get is a blank page nothing is echoed to the page

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.