我刚刚完成了一个小型注册表单,您可以在其中输入用户名、密码和消息,它会使用以下列将其插入到 mysql 中:
username password id message date time country recover_id
这些意味着:
ID = a random generated ID, for later use.
Time = Time of creation
Date = date of creation
Country = empty, later use..
Recover_id = the ID of the registration.
注册后,我这样做:
// Let's store these into a session now.
$username = $_SESSION['user'];
$password = $_SESSION['pass'];
//Now let's refresh the page, to a different header.
header('Location: recover.php?recovery=success');
}
存储用户名并传递给 session ,然后创建一个新的 header 。
然后
}
else if (isset($_GET['recovery']) && $_GET['recovery'] == 'success')
{
$fetch = $connect->query("SELECT * FROM users WHERE username = ':username' LIMIT 1");
$fetch->bindValue(':username', $_SESSION['user']);
$fetch->execute();
while($row = mysql_fetch_array($fetch)) {
echo $row['recover_id'];
}
}
我想尝试转到指定用户名列,并从中获取信息,例如 recovery_id 或 ID 本身。
但这不
Warning: mysql_fetch_array() expects parameter 1 to be resource, object given in C:\xampp\htdocs\recover\recover.php on line 103
我知道我做错了什么,但是什么? 谢谢!
最佳答案
由于您使用的是 pdo (那里做得很好=))你不能调用 mysql_*
函数。
使用 PDO 的 fetch()
方法代替。
while($row = $fetch->fetch( PDO::FETCH_ASSOC ) ) {
echo $row['recover_id'];
}
您需要将 PDO::FETCH_ASSOC
作为参数传递,以便能够使用命名索引检索数据。
关于php - 从指定刚刚注册的用户获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15582402/