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 8930605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:55:40+00:00 2026-06-15T08:55:40+00:00

I am trying to create a signup form that checks if the user exists

  • 0

I am trying to create a signup form that checks if the user exists in the database, I inserted a sample user and when I tried signing up with that user it didn’t say its already been taken. What have I done wrong?

The JavaScript:

function formSubmit()
    {
    document.getElementById('email_valid').innerHTML = '';

    var temail=document.forms["signup_form"]["temail"].value.replace(/^\s+|\s+$/g, '');


      var atpos=temail.indexOf("@");
        var dotpos=temail.lastIndexOf(".");
        if (atpos<1 || dotpos<atpos+2 || dotpos+2>=temail.length)
          {
          //alert("Not a valid e-mail address");
          setTimeout(function(){document.getElementById('email_valid').innerHTML = '<br/>Email must be valid...';},1000);
          var temailsub=0;
          }
          else
          {
          $.post('/resources/forms/signup/email.php',{email: temail}, function(data){
            document.getElementById('email_valid').innetHTML = data;
            if(data.exists){
                    document.getElementById('email_valid').innetHTML = '<br/>The email address you entered is already in use.';
                    var temailsub=0;
                }else{
                    var temailsub=1;
                }
            }, 'JSON');
          }
    if(temailsub==1e)
      {
        setTimeout(function(){document.getElementById("signup_form").submit();},1000);
      }
      else
      {

        return false;
      }
    }

The PHP file (email.php):

<?php
header('content-type: text/json');
require_once $_SERVER['DOCUMENT_ROOT']."/resources/settings.php";
$query = $pdo->prepare("SELECT * FROM users WHERE email=:email");
$query->execute(array(
    ":email"=> $_POST['email']
));
echo json_encode(array('exists' => $query->rowCount() > 0));
?>

I have checked and double checked the code, I still cannot see why its not detecting that the email has already been used… what do i need to do to fix this and avoid this in the future?

  • 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-06-15T08:55:41+00:00Added an answer on June 15, 2026 at 8:55 am

    The problem is that PDOStatement::rowCount() returns the number of rows affected by the last SQL statement. You are performing a SELECT so this value will always be 0. SELECT does not affect any rows. Instead you need to count the number of rows:

    $query = $pdo->prepare("SELECT COUNT(*) FROM users WHERE email=:email");
    $query->execute(array(
        ":email"=> $_POST['email']
    ));
    $rows = $query->fetchColumn();
    
    echo json_encode(array('exists' => $rows);
    

    Also from jtheman’s comment above, you should replace innetHTML with innerHTML in your JavaScript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a very simple email signup form, where the user can
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
i am trying to create a signup form for my django app. for this
I'm trying to create a simple form that will validate that the first password
I'm trying to create default seed records for every user that signs up to
I'm trying to create a form where a user can type in their email
I was trying to sign-up Twitter today and I noticed that their registration form
I'm new to rails! Ok, I am trying to set up a user signup
When a user is editing data in a form that is populated from a
I'm trying to create a messagebox that is fixed to the bottom of a

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.