我正在尝试检查是否已经使用 PDO 注册了电子邮件,但到目前为止我还没有找到这样做的好方法。这就是我到目前为止所拥有的。如果有帮助,连接变量是“$con”。另外,我是否需要在同一个文档中使用连接变量,或者它是否会在包含工作的文档中?
<link rel="stylesheet" type="text/css" href="css\errors.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
}
?>