1

问题:插入数据库后我无法获取电子邮件值。

编辑:

修正:我的问题被$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()); 
    }

插入数据库有效。

提前感谢您的帮助。

4

2 回答 2

0
'&key='$activation;
'&key=' . $activation;

'&key=' 和 $activation 之间缺少一个点;

于 2013-05-10T06:58:40.237 回答
0

尝试这个

  $message .= $WEBSITE_URL . "/activate.php?email=" . urlencode($email) . "&key=".$activation;

无论如何使用这个sha1(uniqid(mt_rand(), true));

于 2013-05-10T07:09:24.510 回答