请帮助我收到错误可捕获的致命错误:无法将类stdClass的对象转换为第22行的E:\ xampp \ htdocs \ codd \ c30.php中的字符串,用于登录处理页面,用户名为“adminit”& 'xampp'中的密码欢迎我的代码是
<?php
$dsn = "mysql:dbname=userdetails;host=localhost;port=3306";
$username2 = "%";$password2 = "";
if (!defined('PDO::ATTR_DRIVER_NAME'))
{
echo 'PDO unavailable';
}
else
{
echo 'PDO is running okay';
}
try
{
$userid=$_POST["username"];
$password=$_POST["password"];
$secpass=password_hash($password,PASSWORD_DEFAULT);
$con5 = new PDO($dsn, $username2, $password2);
$con5->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,(string)result['password'])
&& isset($_POST['Login'])
&& isset($_POST['username'])
&& isset($_POST['password']))
{//$x33=password_verify($password,$prev);
//header('location:c31.php');
echo "your password matches";
}
else
{//$x34=password_verify($password,$prev);
// header('location:cas1.php');
echo "youhavetologin again";
}
}
catch(ErrorException $e)
{
$e->getMessage();
}
finally
{
unset($_POST['Login']);unset($_POST['username']);unset($_POST['password']);
$con5 = NULL;
}
答案 0 :(得分:0)
代码中的错误
更新您发布的问题
$result['password'] = $stmt7->fetch(PDO::FETCH_OBJ);
$con5->commit();
if(password_verify($secpass,(string)result['password'])
到
$result = $stmt7->fetch(PDO::FETCH_OBJ);
$con5->commit();
if(password_verify($secpass,(string)$result->password)
再试一次