Bendude14 Posted July 4, 2008 Share Posted July 4, 2008 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 https://forums.phpfreaks.com/topic/113184-solved-check-if-user-exists-and-if-so-get-password/ Share on other sites More sharing options...
Bendude14 Posted July 4, 2008 Author Share Posted July 4, 2008 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 https://forums.phpfreaks.com/topic/113184-solved-check-if-user-exists-and-if-so-get-password/#findComment-581540 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.