I finally figured it out, for anyone who may be looking for the same info.
if (isset($_POST['submit']))
{
if(empty($_POST['fname']) ||
empty($_POST['lname']) ||
empty($_POST['email']) ||
empty($_POST['password']))
{
if(empty($_POST['fname']))
{
$fnamerr = "<font color=\"red\">Please enter your first name</font>";
}
Again, I did the same thing for last name, email and password for if they are empty. Then:
} else if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
{
$emailerr = "<font color=\"red\">Please enter a valid email address</font>";
$submitted_firstname = htmlentities($_POST['fname'], ENT_QUOTES, 'UTF-8');
$submitted_lastname = htmlentities($_POST['lname'], ENT_QUOTES, 'UTF-8');
$submitted_email = htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8');
} else if (!empty($_POST['fname']) &&
!empty($_POST['lname']) &&
!empty($_POST['email']) &&
!empty($_POST['password']))
{
$query = "
SELECT
1
FROM users
WHERE
email = :email
";
$query_params = array(
':email' => $_POST['email']
);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die ("Failed to run query: " . $ex->getMessage());
}
$row = $stmt->fetch();
if ($row)
{
$emailerr2 = "<font color=\"red\">This email address is already registered</font>";
$submitted_firstname = htmlentities($_POST['fname'], ENT_QUOTES, 'UTF-8');
$submitted_lastname = htmlentities($_POST['lname'], ENT_QUOTES, 'UTF-8');
$submitted_email = htmlentities($_POST['email'], ENT_QUOTES, 'UTF-8');
} else
{
Then I run the code for inserting the info into the db table. This worked beautifully. Hopefully nothing else comes up. Thanks for the comments and help.