[英]How to check if email exists in my database phpmyadmin
我的register.php文件
我正在嘗試檢查在phpmyadmin上我的數據庫中是否已經存在在表單輸入中注冊的電子郵件。 我如何才能做到這一點而又不破壞我的代碼。
<?php
session_start();
if( isset($_SESSION['user_id']) ){
header("Location: index.php ");
}
require 'database.php';
$message = '';
if(!empty($_POST['email']) && !empty($_POST['password'])):
// Enter the new user in the database
$sql = "INSERT INTO signup (name, surname,email, password) VALUES (:name, :surname,:email, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':name', $_POST['name']);
$stmt->bindParam(':surname', $_POST['surname']);
$stmt->bindParam(':email', $_POST['email']);
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
if( $stmt->execute() ):
$message = 'Successfully created new user';
else:
$message = 'Sorry there must have been an issue creating your account';
endif;
endif;
?>
這是一個使用PDO的函數,如果已經存在電子郵件,它將返回1:
function check_mail_exist($con, $mail){
$sql = $con->prepare("SELECT * FROM table_name WHERE column_mail='".$mail."'; ");
$sql->execute();
$result = $sql->rowCount();
if ($result > 0)
return 1;
return 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.