我正在编写一个脚本,将忘记密码的链接发送到用户的电子邮件地址。我创建了一个名为“recoveryemails_enc”的表,它将保存用户的电子邮件地址、密钥和一个扩展日期。用户电子邮件地址是从我的“用户”表中提取的。当我运行脚本时,它会创建带有密钥和到期日期的正确链接,但数据并未插入到数据库中。下面是我的代码。我不确定我做错了什么。
$result = mysql_query("SELECT email from users WHERE email = '$email' AND active='1'") or die(mysql_error());
$expFormat = mktime(date("H"), date("i"), date("s"), date("m") , date("d")+3, date("Y"));
$expDate = date("Y-m-d H:i:s",$expFormat);
$key = md5($email . rand(0,10000) .$expDate);
$no_of_rows = mysql_num_rows($result);
if ($no_of_rows > 0) {
$result = mysql_fetch_array($result);
$query = mysql_query("INSERT INTO recoveryemails_enc(email, Key, expDate) VALUES('$email', '$key', '$expDate')");
$passwordLink = "<a href=\"?a=recover&email=" . $key . "&u=" . urlencode(base64_encode($email)) . "\">http://www.mywebsite.com/forgotpw.php?a=recover&email=" . $key . "&u=" . urlencode(base64_encode($email)) . "</a>";
我用来创建表的编辑命令:
CREATE TABLE IF NOT EXISTS `recoveryemails_enc` (
ID
bigint(20) unsigned zerofill NOT NULL auto_increment,
email
bigint(20) NOT NULL,
Key
varchar(32) NOT NULL,
expDate
datetime NOT NULL,
PRIMARY KEY ( ID
)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;