問題:插入數據庫後無法獲取電子郵件值。爲什麼在插入數據庫後無法使用數據與PHP
編輯:
修正: 我的問題是$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: [email protected]';
$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());
}
插入到數據庫的工作原理。
在此先感謝您的幫助。
還是需要從DATEBASE回讀數據,插入後再次使用? – Markus 2013-05-10 06:53:56
反正使用 sha1(uniqid(mt_rand(),true)); – Yogus 2013-05-10 06:55:52
okey tnx暗示 – Markus 2013-05-10 07:08:43