gpt4 book ai didi

php - 匹配选择最新行的主要问题

转载 作者:行者123 更新时间:2023-11-29 14:54:53 25 4
gpt4 key购买 nike

我在选择数据库中最新/匹配的行时遇到了很大的困难。

例如:

$query = "SELECT * FROM `Password_Reset`";
$request = mysql_query($query,$connection) or die(mysql_error());
$result = mysql_fetch_array($request);

$result['token'] 无论如何每次运行查询时都会获取第一行。

我很确定这与我的选择查询不够具体有关,但我还没有找到匹配它的方法。

更具体一些。这是整个查询:

$query = "SELECT * FROM `Password_Reset`";
$request = mysql_query($query,$connection) or die(mysql_error());
$result = mysql_fetch_array($request);

$token = $result['token'];

$alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcedfghijklmnopqrstuvwxyz1234567890";
$rand = str_shuffle($alpha);
$salt = substr($rand,0,40);
$hashed_password = sha1($salt . $_POST['Password']);
$user_email = $result['email'];





// these should match, and do so every where else on my other pages and in the db, I'm just not able to pull the corresponding $token. its taking the $token in the first row every time.
if($get_token == $token) {
header("Location: http://www.cysticlife.org/index.php");
exit;
}else{

if(empty($_POST['Password'])) {
$valid = false;
$error_msgs[] = 'Whoops! You must enter a password.';
}

if($_POST['Password'] != $_POST['passwordConfirm'] || empty($_POST['Password'])) {
$valid = false;
$error_msgs[] = "Your password entries didn't match...was there a typo?";
}

if($valid) {
$query = "UPDATE `cysticUsers` SET `encrypted_password` = '$hashed_password' WHERE `Email` = '$user_email'";

mysql_query($query,$connection);
}


}
}

提前致谢

最佳答案

如果您想按行提交到数据库的时间对行进行排序,则需要向表中添加 ID 字段(如果您还没有 ID 字段)。

这可能是向表中添加名为 id 的字段、将其设置为索引并使用 auto_increment 的最简单方法。然后,您可以简单地按 ID 对行进行排序:

SELECT * FROM `Password_Reset` ORDER BY `id` ASC

顺便说一句,如果您只需要第一行,最好在查询中添加LIMIT 1,以获得更好的性能。

关于php - 匹配选择最新行的主要问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4902958/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com