本文介紹了如何檢查郵箱是否已經注冊?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試檢查是否已經使用 PDO 注冊了電子郵件,但到目前為止我還沒有找到一個好的方法.這就是我迄今為止所擁有的.如果有幫助,連接變量是$con".另外,我需要在同一個文檔中使用連接變量還是在包含的文檔中工作?
I am trying to check to see if an email is already registered using PDO, but I have not found a good way to do this so far. This is what I have so far. And the connection variable is "$con" if that helps. Also, do I need the connection variable in the same document or will it being in a document that is included work?
<link rel="stylesheet" type="text/css" href="csserrors.css">
<?php
require 'header.php';
if (!$_POST['submit']) {
?>
<html>
<a href="register.html">Regsiter here!</a>
<?php
} else {
require 'connect.php';
$firstname = ($_POST['firstname']);
$lastname = ($_POST['lastname']);
$email = ($_POST['email']);
$password = ($_POST['password']);
$passwordconf = ($_POST['passwordconf']);
$errorfields = "<p class='errormsg'>Please fill out all the fields!</p>";
if (empty($firstname) || empty($lastname) || empty($email) || empty($password) || empty($passwordconf)) {
echo "$errorfields";
}
$erroremail = "<p class='errormsg'>Email is not in name@domain format!</p>";
$regex = "/^[a-z0-9]+([_.-][a-z0-9]+)*@([a-z0-9]+([.-][a-z0-9]+)*)+.[a-z]{2,}$/i";
if (!preg_match($regex, $email)) {
echo "$erroremail";
}
$errorpassword = "<p class='errormsg'>You passwords do not match!</p>";
if ($password != $passwordconf) {
echo "$errorpassword";
}
//this is where email is checked
}
?>
推薦答案
試試這個,用你的連接憑據填寫 DB_NAME、DB_USER_NAME 和 DB_USER_PASS 或者使用 $con 變量,如果一切都正確設置為 PDO 對象:
Try this, fill in DB_NAME, DB_USER_NAME, and DB_USER_PASS with your connection credentials or use the $con variable if everything is set up correctly as a PDO object with it:
$con = new PDO( 'mysql:host=localhost;dbname=DB_NAME;charset=UTF-8', 'DB_USER_NAME', 'DB_USER_PASS' );
$query = $con->prepare( "SELECT `email` FROM `tbl_name` WHERE `email` = ?" );
$query->bindValue( 1, $email );
$query->execute();
if( $query->rowCount() > 0 ) { # If rows are found for query
echo "Email found!";
}
else {
echo "Email not found!";
}
這篇關于如何檢查郵箱是否已經注冊?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!