I'm working on a script to send a forgot password link to a users email address. I created a table called "recoveryemails_enc" that will hold the users email address, Key, and a expdate. The users email address is pulled from my "users" table. When I run the script, it creates the proper link with the key and expiration date but the data is not being inserted into the database. Here is my code below. I'm not sure what I'm doing wrong.
$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>";
Edit command I used to create my table:
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 ;
$url = '?blabla='.$keyetc, and then passing it to your<a>:$passwordLink = '<a href="'.$url.'">'.$url.'</a>'