检查是否已收到电子邮件

时间:2016-03-06 02:23:29

标签: php mysql

在我的PHP文件中,我想在将数据插入mysql数据库之前检查是否已经收到电子邮件。

我无法发现我的代码有任何问题,但它无法正常工作。

PHP代码:

<?php


$conn = mysqli_connect("s.amazonaws.com", "username", "pass", "SellerAccounts");

//If statement echos back to the browser if we connected to the server or not.

    //Store the data from the POST (text from the user) into a variable.
    $Sellers_CompanyName = $_POST["SellersCompanyName"];
    $Sellers_CompanyWebsite = $_POST["SellersCompanyWebsite"];
    $Sellers_IndustryName = $_POST["SellersIndustryName"];
    $Sellers_SecondaryIndustryName = $_POST["SellersSecondaryIndustryName"];
    $Sellers_FirstContactFirstName = $_POST["SellersFirstContactFirstName"];
    $Sellers_FirstContactLastName = $_POST["SellersFirstContactLastName"];
    $Sellers_FirstContactNumber = $_POST["SellersFirstContactNumber"];
    $Sellers_FirstContactEmail = $_POST["SellersFirstContactEmail"];
    $Sellers_SecondContactFirstName =    $_POST["SellersSecondContactFirstName"];
    $Sellers_SecondContactLastName = $_POST["SellersSecondContactLastName"];
    $Sellers_SecondContactNumber = $_POST["SellersSecondContactNumber"];
    $Sellers_SecondContactEmail = $_POST["SellersSecondContactEmail"];
    $Sellers_Password = $_POST["Password"];


    $result = mysql_query("SELECT * FROM user_info WHERE     Sellers_FirstContactEmail = '".$Sellers_FirstContactEmail."'");

            if ( mysql_num_rows($result) > 0 ){

     echo("Email is already in use");

            }else{
 //
    $statement = mysqli_prepare($conn, "INSERT INTO user_info                (Sellers_CompanyName, Sellers_CompanyWebsite, Sellers_IndustryName,     Sellers_SecondaryIndustryName, Sellers_FirstContactFirstName, Sellers_FirstContactLastName, Sellers_FirstContactNumber, Sellers_FirstContactEmail, Sellers_SecondContactFirstName, Sellers_SecondContactLastName, Sellers_SecondContactNumber, Sellers_SecondContactEmail, Sellers_Password) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");

mysqli_stmt_bind_param($statement, "sssssssssssss", $Sellers_CompanyName,    $Sellers_CompanyWebsite, $Sellers_IndustryName, $Sellers_SecondaryIndustryName, $Sellers_FirstContactFirstName, $Sellers_FirstContactLastName, $Sellers_FirstContactNumber, $Sellers_FirstContactEmail, $Sellers_SecondContactFirstName, $Sellers_SecondContactLastName, $Sellers_SecondContactNumber, $Sellers_SecondContactEmail, $Sellers_Password);
    mysqli_stmt_execute($statement);
    mysqli_stmt_close($statement);

    if(mysqli_query($connection, $sql_query)){
       // echo" Data insertion success...";
     }
            }

mysqli_close($conn);

?>

我可以插入所有内容并连接到数据库

2 个答案:

答案 0 :(得分:1)

您不能将MySQL函数与MySQLi函数混合使用。此外,您的关联为$conn,因此使用$connection将无效。

<?php

$conn = mysqli_connect("s.amazonaws.com", "username", "pass", "SellerAccounts");

$Sellers_CompanyName = $_POST["SellersCompanyName"];
$Sellers_CompanyWebsite = $_POST["SellersCompanyWebsite"];
$Sellers_IndustryName = $_POST["SellersIndustryName"];
$Sellers_SecondaryIndustryName = $_POST["SellersSecondaryIndustryName"];
$Sellers_FirstContactFirstName = $_POST["SellersFirstContactFirstName"];
$Sellers_FirstContactLastName = $_POST["SellersFirstContactLastName"];
$Sellers_FirstContactNumber = $_POST["SellersFirstContactNumber"];
$Sellers_FirstContactEmail = $_POST["SellersFirstContactEmail"];
$Sellers_SecondContactFirstName =    $_POST["SellersSecondContactFirstName"];
$Sellers_SecondContactLastName = $_POST["SellersSecondContactLastName"];
$Sellers_SecondContactNumber = $_POST["SellersSecondContactNumber"];
$Sellers_SecondContactEmail = $_POST["SellersSecondContactEmail"];
$Sellers_Password = $_POST["Password"];


$result = mysqli_query($conn, "SELECT * FROM user_info WHERE     Sellers_FirstContactEmail = '$Sellers_FirstContactEmail'");

if ( mysqli_num_rows($result) > 0 ){

    echo("Email is already in use");

} else {

$statement = mysqli_prepare($conn, "INSERT INTO user_info                (Sellers_CompanyName, Sellers_CompanyWebsite, Sellers_IndustryName,     Sellers_SecondaryIndustryName, Sellers_FirstContactFirstName, Sellers_FirstContactLastName, Sellers_FirstContactNumber, Sellers_FirstContactEmail, Sellers_SecondContactFirstName, Sellers_SecondContactLastName, Sellers_SecondContactNumber, Sellers_SecondContactEmail, Sellers_Password) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");

mysqli_stmt_bind_param($statement, "sssssssssssss", $Sellers_CompanyName,    $Sellers_CompanyWebsite, $Sellers_IndustryName, $Sellers_SecondaryIndustryName, $Sellers_FirstContactFirstName, $Sellers_FirstContactLastName, $Sellers_FirstContactNumber, $Sellers_FirstContactEmail, $Sellers_SecondContactFirstName, $Sellers_SecondContactLastName, $Sellers_SecondContactNumber, $Sellers_SecondContactEmail, $Sellers_Password);

mysqli_stmt_execute($statement);

mysqli_stmt_close($statement);

    if(mysqli_query($conn, $sql_query)){
        // echo" Data insertion success...";
    }
}

mysqli_close($conn);

?>

答案 1 :(得分:-1)

如何用以下内容替换您的查询?:

$result = mysql_query("SELECT * FROM user_info WHERE Sellers_FirstContactEmail = '".$Sellers_FirstContactEmail."'");

注意在上面使用字符串连接。在您的情况下,您的查询正在尝试查找与字符串“$ Sellers_FirstContactEmail”匹配的电子邮件,这不是您想要的 - 您要检查该变量的值。