Wikipedia:Reference desk/Archives/Computing/2017 November 2

= November 2 =

PHP question
My code for login page handling for multiple concurrent users is failing miserably at the password_verify funtion line with message Catchable fatal error: Object of class stdClass could not be converted to string in E:\xampp\htdocs\codd\c30.php on line 22 setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $con5->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);$con5->beginTransaction; $stmt7=$con5->prepare("SELECT password FROM user_data WHERE userid='$userid'"); $stmt7->execute; $result['password']=$stmt7->fetch(PDO::FETCH_OBJ);$con5->commit; if(password_verify($secpass,$result['password'])&& isset($_POST['Login']) && isset($_POST['username'])&& isset($_POST['password'])) {	echo "your password matches"; } else {  echo "youhavetologin again"; } } catch(ErrorException $e)

{   $e->getMessage; }

finally{

unset($_POST['Login']);unset($_POST['username']);unset($_POST['password']); $con5=NULL; } ?> Replacing if(password_verify($secpass,$result['password']) with if(password_verify($secpass,$result->password yields Warning: password_verify expects parameter 2 to be string, object given in E:\xampp\htdocs\codd\c30.php on line 19 youhavetologin again Please provide substitute code suggestion — Preceding unsigned comment added by Wrought2 (talk • contribs) 09:56, 2 November 2017 (UTC)
 * The problem is that you're not handling the return value from  correctly.  The fetch method returns an array (indexed by column name), but you're assigning it to an element of , not to   itself.  Try instead:
 * and keep your original code for the call to .  The relevant page of the PHP manual is here. Tevildo (talk) 17:30, 2 November 2017 (UTC)
 * A quick follow-up:
 * will explicitly return an array rather than an anonymous object, which will be a better match to the rest of your code. Tevildo (talk) 17:35, 2 November 2017 (UTC)
 * will explicitly return an array rather than an anonymous object, which will be a better match to the rest of your code. Tevildo (talk) 17:35, 2 November 2017 (UTC)
 * will explicitly return an array rather than an anonymous object, which will be a better match to the rest of your code. Tevildo (talk) 17:35, 2 November 2017 (UTC)