问题:插入数据库后,我无法获取电子邮件值。
编辑:
修正:
我的问题是$to = $_POST['$email'];
错误的价值。它应该是$to = $_POST['email'];
。
问题是因为我有$给予价值。
这是我创建激活码的方式:
$activation = sha1(uniqid(rand(), true));
这是我声明数据库插入查询的方式:
$query = "INSERT INTO users (activation, email) VALUES (:activation, :email)";
这里我填充插入查询的参数:
$query_params = array(
':activation' => $activation,
':email' => $_POST['email']
);
...以下是我如何通过执行查询并发送电子邮件将数据添加到我的数据库:
try
{
// Execute the query to create the user
$stmt = $db->prepare($query);
$stmt->execute($query_params);
if ($stmt->rowCount() > 0) { //If the Insert Query_params was successfull.
echo 'even gets to here.';
// Send the email:
$to = $_POST['email'];
$subject = 'Registeerimis kinnitus';
$from = 'From: mymail@gmail.com';
$WEBSITE_URL = "http://mysite.com";
$message = " Kasutaja aktiveerimiseks, palun vajutage aadressile:\n\n";
$message .= $WEBSITE_URL . "/activate.php?email=" . urlencode($to) . "&key=".$activation;
mail($to, $subject, $message);
}
}
catch(PDOException $ex)
{
// Note: On a production website, you should not output $ex->getMessage().
// It may provide an attacker with helpful information about your code.
die("Failed to run query: " . $ex->getMessage());
}
数据库的插入工作。
提前感谢您的帮助。
答案 0 :(得分:0)
'&key='$activation;
'&key=' . $activation;
在'& key ='和$ activation;
之间缺少一个点答案 1 :(得分:0)
试试这个
$message .= $WEBSITE_URL . "/activate.php?email=" . urlencode($email) . "&key=".$activation;
无论如何使用此sha1(uniqid(mt_rand(), true));