![](/img/trans.png)
[英]What should i add to the following code so that it can save button value onclick in php variable and i will send it in the email
[英]Where should I add the code so that it checks whether email exists or not?
我應該在哪里添加代碼以便它檢查電子郵件是否存在? 我已將所有詳細信息插入數組中,我應該如何調用特定屬性以及應該在哪里實現它,以便它檢查我的數據庫中是否存在不止一封電子郵件?
<?php
$connect = new PDO("mysql:host=localhost;dbname=testing", "root", "");
$message = '';
if(isset($_POST["email"]))
{
sleep(3);
$query = "
INSERT INTO tbl_login
(first_name, last_name, gender, email, password, address, mobile_no) VALUES
(:first_name, :last_name, :gender, :email, :password, :address, :mobile_no)
";
$password_hash = password_hash($_POST["password"], PASSWORD_DEFAULT);
$user_data = array(
':first_name' => $_POST["first_name"],
':last_name' => $_POST["last_name"],
':gender' => $_POST["gender"],
':email' => $_POST["email"],
':password' => $password_hash,
':address' => $_POST["address"],
':mobile_no' => $_POST["mobile_no"]
);
$statement = $connect->prepare($query);
if($statement->execute($user_data))
{
$message = '
<div class="alert alert-success">
Registration Completed Successfully
</div>
';
header("location:login.php");
}
else
{
$message = '
<div class="alert alert-success">
There is an error in Registration
</div>
';
}
}
?>
您可以編寫一個 if 語句來執行查詢並將結果值存儲到變量中。 現在,如果該變量為空,則表示數據庫尚未注冊相同的電子郵件。
$sql = 'SELECT email from tbl_login WHERE email=:email'
$params = [
:email => $_POST['email']
] ;
// Now the if statement which checks if the entered email already exists in the DB
$stmt = $connect->prepare($sql)
$stmt->execute($params)
if(!$temp = $stmt->fetc())
{ // Email doesn't exist in the DB, procees to insert it}
else
{ // Email already exists in the DB}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.