php - 为什么我用PHP插入数据库后不能使用数据

标签 php mysql email send

问题:插入数据库后无法获取email值。

编辑:

固定: 我的问题是 $to = $_POST['$email']; 给出了错误的值。它应该是 $to = $_POST['email'];。 问题是因为我有 $ 来提供值(value)。

这是我创建激活码的方式:

$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()); 
    }

插入数据库有效。

在此先感谢您的帮助。

最佳答案

试试这个

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

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

关于php - 为什么我用PHP插入数据库后不能使用数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16476723/

相关文章:

PHP:根据一个键上的组从 Json 数组创建多个 Json 数组

mysql - Spring JPA 选择集合中的元素

c# - 如何检测 .NET 中的电子邮件大小问题

java - 尝试发送邮件空指针异常

html - 如何创建 HTML 电子邮件以在所有电子邮件客户端中使用?

php - 将类添加到 Wordpress 图像 <a> anchor 元素

php - Mysqli 插入 id 返回 null

php - 将用户重定向到 php 中的同一页面问题

php - 在 easyphp 上使用 PHP 导入和导出 MySQL 数据库

mysql - 无法保存存储过程 : #1064 - You have an error in your SQL syntax;