Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7129571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:15:24+00:00 2026-05-28T11:15:24+00:00

For some reason my form is not checking the database to see if the

  • 0

For some reason my form is not checking the database to see if the email already exists. Are you able to identify anything wrong with my code?

// If the form submit button is set and the email and zip fields are not empty, proceed and process 
if (isset($_POST['submit']) && !empty($_POST['email']) && !empty($_POST['zip'])) {  

    // Create variables for form input fields
    $email = $_POST['email'];
    $zip = $_POST['zip'];

    // Create an array to capture errors
    $errors = array();

    // Create variable to capture success message
    $success = "Thanks for signing up!";

    // Email Validation
    // Check to see if user entered a valid email
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $errors[] = "Invalid email address.";
    }
    // Check email length
    if (strlen($email) < 6) {
        $errors[] = "Sorry your email is too short.";
    }
    // Check email length
    if (strlen($email) > 50) {
        $errors[] = "Sorry your email is too long.";
    }

    // Zip Code Validation
    // Check to see if zip code is a number
    if (!is_numeric($zip)) {
        $errors[] = "Zip code must be a number.";
    }
    // Check to see if zip code equals 5 characters
    if (strlen($zip) != 5) {
        $errors[] = "Sorry not a valid zip code.";
    }

    // Include database config file and establish db connection
    require("includes/config.php");
    $connection = mysql_connect(DB_HOST,DB_USERNAME,DB_PASSWORD) or die("Database Connection Error");
    $database = mysql_select_db(DB_NAME) or die("No Database Found");

    // Check to see if email already exists in database
    $email_check_query = "SELECT email FROM shotgun";
    $run_email_check_query = mysql_query($email_check_query);

    // If MySQL query returns any results, user has already signed up
    if (mysql_fetch_assoc($run_email_check_query) == $email) {
        $errors[] = "Looks like you already signed up...";
    }

    // If there are no errors above run this block of code
    if (count($errors) == 0) {

        // Include database config file and establish db connection
        require("includes/config.php");
        $connection = mysql_connect(DB_HOST,DB_USERNAME,DB_PASSWORD) or die("Database Connection Error");
        $database = mysql_select_db(DB_NAME) or die("No Database Found");

        // Insert email and password into database
        $insert_email_query = "INSERT INTO shotgun (email,zip) VALUES ('$email','$zip')";
        $run_insert_email_query = mysql_query($insert_email_query);
    }   
} 
?>

Site

</head>
<body>
    <header>
        <div class="logo">
            <h1>Site</h1>
        </div>
    </header>
    <div class="content">
        <div class="comingsoon"></div>
        <h1>Sign Up Now</h1>
        <p class="description">Description</p>
        <form action="index.php" method="post">
            <input type="email" class="email" name="email" placeholder="Email Address">
            <input type="text" class="zip" name="zip" max="5" placeholder="Zip Code">
            <input type="submit" class="submit" name="submit" value="Submit">
            <span class="errors">
            <?php 
                if (count($errors) != 0) { 
                    foreach($errors as $error) { 
                        echo $error . "<br />";
                    }
                } else {
                    echo $success; 
                }
            ?>
            </span>
        </form>
    </div>
    <footer><a href="test.com" title="test"></a></footer>
</body>

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:15:25+00:00Added an answer on May 28, 2026 at 11:15 am
    $email_check_query = "SELECT email FROM datingshotgun";
    

    should be

    $email_check_query = "SELECT email FROM datingshotgun WHERE email='$email'";
    

    Right now you allways query ALL emails and compare the new email to the first in the DB.

    EDIT: After tracking your code, you need:

    $dbemail=mysql_real_escape_string($email, $connection);
    $email_check_query = "SELECT email FROM datingshotgun WHERE email='$dbemail'";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason everything works with my code but the form will not submit.
For some reason I never see this done. Is there a reason why not?
For some reason, my code displays correctly in all browsers except IE8. <form dojoType=dijit.form>'
For some reason the script below is not working. This is the code I
For some reason my search form is not working correctly when my app is
form some reason this seems to be working fine in FF but not in
For some reason, my form is always at 100% opacity. I've tried changing it
Have a simple form (only extract fields here) but for some reason the JQserilization
I've created a login submit form in HTML but for some reason user/password autocompletion
For some reason, Section 1 works but Section 2 does not. When run in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.