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
}
?>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…