【发布时间】:2011-02-04 21:08:03
【问题描述】:
我在选择数据库中最新/匹配的行时遇到了很大问题。
例如:
$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);
}
}
}
提前致谢
【问题讨论】:
标签: php mysql variables select