我有一个更新 MD5 加密密码的表单。在此过程中,密码字段已更新为随机令牌,然后作为链接的一部分通过电子邮件发送给用户,然后该令牌用于匹配要更新的帐户。
我必须检查两个表,因为我们将管理员和用户分成不同的表。我收到以下 SQL 错误。SQL 和 CodeIgniter 对我来说都很新。
SQL 错误:
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UNION UPDATE staff SET staff_password = '098f6bcd4621d373cade4e832627b4f6' WHERE' at line 1
UPDATE admin SET admin_password = '098f6bcd4621d373cade4e832627b4f6' WHERE admin_password = 'fd323219f98afd367fee9907173012db' UNION UPDATE staff SET staff_password = '098f6bcd4621d373cade4e832627b4f6' WHERE staff_password = 'fd323219f98afd367fee9907173012db'
型号代码:
public function update_password() {
$sql = "UPDATE admin SET admin_password = ? WHERE admin_password = ? UNION UPDATE staff SET staff_password = ? WHERE staff_password = ?";
$password = $this->input->post('password');
$token = $this->input->post('token');
$query = $this->db->query($sql, array($password, $token, $password, $token));
if($query->num_rows() == 1) {
return true;
} else {
return false;
}
}
令牌在视图中设置为隐藏字段:
<input type="hidden" name="token" value="<?php echo $token;?>" id="token">