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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.