gpt4 book ai didi

php - 检查电子邮件是否已被占用

转载 作者:行者123 更新时间:2023-11-29 21:18:23 26 4
gpt4 key购买 nike

在我的 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);

?>

我可以插入一切正常并连接到数据库

最佳答案

您不能将 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);

?>

关于php - 检查电子邮件是否已被占用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35822356/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com