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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:04:02+00:00 2026-06-15T18:04:02+00:00

I’ve spent some time looking on SO for an answer to this and have

  • 0

I’ve spent some time looking on SO for an answer to this and have found some related issues, but nothing quite like mine…as usual….

I’ve got a fairly simple php/jquery ajax registration page that is working right up until the ajax callback. What I mean is the form data is passing to php and inserting into the db but when the php response is supposed to come back all that happens is the response displays in the browser. I’ve followed the logs, checked fiddler, re-written the code with/without json, and anothing seems to change. The odd thing is I have another form on a different page that is set up exactly the same way and everything works there perfectly. The only difference I can find between the two pages is the Request Headers of the php file. The one that works accepts json and the one the other one doesn’t, but I have no idea if that means anything . . . I’m kind of grabbing for anything at this point.

So, without further delay, here is my code. Any thoughts/input are greatly appreciated. Thank you!

<!DOCTYPE html>

<head>


    <link rel="stylesheet" type="text/css" href="mobile.css" media="screen and (max-device-width: 480px)" /> 
    <!--[if IE]>
        <link rel="stylesheet" type="text/css" media="screen and (min-width: 481px)" href="IEjoin.css" />
    <![endif]-->
    <script src="jquery-1.8.2.min.js" type="text/javascript"></script>
    <script src="register.js" type="text/javascript"></script>
    <script src="jquery.placeholder.js" type="text/javascript"></script>

</head>

<body>

    <div id="wrapper">
        <div id="logo">
        </div>
        <div id="headline">
            <h1>Create your account</h1>
        </div>
        <div id="container">
            <form id="register" action="form.php" method="post">
                <ul>
                    <li id="first_name">
                        <input name="fname" type="text" value="" id="fname" placeholder="First Name" maxlength="30">
                        <div class="error"></div>
                    </li>
                    <li id="last_name">
                        <input name="lname" type="text" value="" id="lname" placeholder="Last Name" maxlength="30">
                        <div class="error"></div>
                    </li>
                    <li id="email_address">
                        <input name="email" type="text" value="" id="email" placeholder="Email Address" maxlength="60">
                        <div class="error"></div>
                    </li>
                    <li id="uname">
                        <input name="username" type="text" value="" id="username" placeholder="Username" maxlength="15">
                        <div class="error"></div>   
                    </li>
                    <li id="pword">
                        <input name="password" type="password" value="" id="password" placeholder="Password">
                        <div class="error"></div>
                    </li>
                    <li id="gender_select">
                        <select id="gender" name="gender">
                            <option value="" selected="selected">Select your gender</option>
                            <option value="male">Male</option>
                            <option value="female">Female</option>
                            <option value="unspecified">Unspecified</option>
                        </select>
                    </li>
                    <li id="submit_button">
                        <button id="register_button" class="register_button_disabled">Create Account</button>
                    </li>
                </ul>
            </form>
            <script> $('input[placeholder]').placeholder();</script>
        </div>
    </div>
</body>

$(document).ready(function() {



function validateEmail(email) {
    var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
    return emailReg.test(email);
}
function submitButton() {
    if (($("#first_name").hasClass("good")) && ($("#email_address").hasClass("good")) && ($("#uname").hasClass("good")) && ($("#pword").hasClass("good")) ){
        $("#register_button").removeAttr("disabled");
        $("#register_button").removeClass("register_button_disabled").addClass("register_button");
    } else {
        $("#register_button").attr("disabled", "disabled");
        $("#register_button").removeClass("register_button").addClass("register_button_disabled");
    }
}
$("body").mousedown(submitButton);
$("body").keyup(submitButton);
$("body").hover(submitButton);
$("body").mouseover(submitButton);
$("#fname").keydown(function(){
    $("#first_name").removeClass("required");
    $("#first_name div").html("");
});
$("#fname").bind ("keyup mousedown",function(){
    if(this.value===""){
        $("#first_name").removeClass("good").addClass("wait");
    } else {
        $("#first_name").removeClass("wait").addClass("good");
    }       
});
$("#fname").blur(function(){
    if(this.value===""){
        $("#first_name").removeClass("good").addClass("required");
        $("#first_name div").html("Please enter your first name");
    } else {
        $("#first_name").removeClass("wait").addClass("good");
    }       
});
$("#email").keydown(function(){
    $("#email_address").removeClass("required");
    $("#email_address div").html("");
});
$("#email").bind ("keyup mousedown",function(){
    var email = this.value;
    var emailLength = email.length;
    if (emailLength<=4){
        $("#email_address").removeClass("good").addClass("wait");
    } else {
        $("#email_address").removeClass("wait").addClass("good");
    }       
});
$("#email").blur(function(){
    var email = this.value;
    var emailLength = email.length;
    if ((emailLength<=4) || (!validateEmail(this.value))) {
            $("#email_address").removeClass("good").addClass("required");
        $("#email_address div").html("Please use a valid email address");
    } else if (emailLength>=3){
        $.ajax({
            type: "POST",
            cache: false,
            url: "Check.php",
            data: "email="+email,
            dataType: "json",
            success: function(data) { 

                if (data.status === "success") {
                    $("#email_address").removeClass("good").addClass("required");
                    $("#email_address div").html("Sorry, that email is already used");}
                else {
                    $("#email_address").removeClass("wait").addClass("good");  
                }
            }
        });
    } else {
         $("#email_address").removeClass("wait").addClass("good");
    }
});
$("#username").keydown(function(){
    var un = this.value;
    var unLength = un.length;
    if(unLength<3){
        $("#uname").removeClass("good").addClass("wait");
    } else {
        $("#uname").removeClass("wait").addClass("good");
    }       
});
$("#username").bind ("keyup mousedown",function(){
    $("#uname").removeClass("required");
    $("#uname div").html("");
});
$("#username").blur(function(){
    var un = this.value;
    var unLength = un.length;
    if(unLength<3){
        $("#uname").removeClass("good").addClass("required");
        $("#uname div").html("Please use at least 3 characters");
    } else if (unLength>=3){
        $.ajax({
            type: "POST",
            cache: false,
            url: "check.php",
            data: "username="+un,
            dataType: "json",
            success: function(data) { 

                if (data.status === "success") {
                    $("#uname").removeClass("good").addClass("required");
                    $("#uname div").html("Sorry, that username is taken");
                } else {
                    $("#uname").removeClass("wait").addClass("good");  
                }
            }
        });
    } else {
        $("#uname").removeClass("wait").addClass("good");
    }
});
$("#password").keydown(function(){
    var pw = this.value;
    var pwLength = pw.length;
    if(pwLength<=5){
        $("#pword").removeClass("good").addClass("wait");
    } else {
        $("#pword").removeClass("wait").addClass("good");
    }       
});
$("#password").bind ("keyup mousedown",function(){
    $("#pword").removeClass("required");
    $("#pword div").html("");
});
$("#password").blur(function(){
    var pw = this.value;
    var pwLength = pw.length;
    if(pw===""){
        $("#pword").removeClass("good").addClass("required");
        $("#pword div").html("Please enter a password");
    }
    if(pwLength<=5){
        $("#pword").removeClass("good").addClass("required");
        $("#pword div").html("Please use at least 6 characters");
    } else {
        $("#pword").removeClass("wait").addClass("good");
    }
});

$("#button").click(function(e) {


    e.preventDefault();     

    $.ajax({
        type: "POST",
        cache: false,
        url: "form.php",
        data: $('#register').serialize(),
        success: function(data) { 
            if (data === "fname") {
                $("#first_name").removeClass("good").addClass("required");
                $("#first_name div").html("Please enter your first name"); 

            } else if (data === "email") {
                $("#email_address").removeClass("good").addClass("required");
                $("#email_address div").html("Please use a valid email address");

            } else if (data === "email2") {
                $("#email_address").removeClass("good").addClass("required");
                $("#email_address div").html("Sorry, that email is already used");

            } else if (data === "username") {
                $("#uname").removeClass("good").addClass("required");
                $("#uname div").html("Please use at least 3 characters");

            } else if (data === "username2") {
                $("#uname").removeClass("good").addClass("required");
                $("#uname div").html("Sorry, that username is taken");

            } else {
                window.location.href = "http://site.com";

        },
        error: function(httpRequest, textStatus, errorThrown) { 
            alert("status=" + textStatus + ",error=" + errorThrown);
        } 
    });             
    return false;

});

});

<?php

$host=""; // Host name 
$username=""; // Mysql username 
$password=""; // Mysql password 
$db_name=""; // Database name 
$tbl_name=""; // Table name  

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// Get values from form 
$fname = mysql_real_escape_string($_POST['fname']);
$lname = mysql_real_escape_string($_POST['lname']);
$email = mysql_real_escape_string($_POST['email']);
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$gender = mysql_real_escape_string($_POST['gender']);

//validate inputs
$emailpull = "SELECT email FROM $tbl_name WHERE email='$email'";
$emailresult=mysql_query($emailpull);
$emailnum=mysql_num_rows($emailresult);

$emailReg = "/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/";

$unpull = "SELECT username FROM $tbl_name WHERE username='$username'";
$unresult=mysql_query($unpull);
$unnum=mysql_num_rows($unresult);

if ($fname == "") {  
$response = "fname";

} elseif ($email == "") {
$response = 'email';

} elseif (!preg_match($emailReg, $email)) {
$response = 'email';

} elseif ($emailnum > 0) {
$response = 'email2';

} elseif (strlen($username)<3) {
$response = 'username'; 

} elseif ($unnum > 0) {
$response = 'username2';

} elseif (strlen($password)<6) {
$response = 'password';

} else {

// Insert data into mysql 
$sql="INSERT INTO $tbl_name(fname,lname,email,username,password,gender)VALUES ('$fname','$lname','$email','$username','$password','$gender')";
}

$result=mysql_query($sql);
if($result)
$response = "success";

// send message back 
echo $response;

?> 

<?php 
// close connection 
mysql_close();
?>
  • 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-15T18:04:04+00:00Added an answer on June 15, 2026 at 6:04 pm

    The click handler for #button has this line which may be the culprit:

    window.location.href = "http://crushonit.com";
    

    This will redirect to that page when the form has no validation errors.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
This could be a duplicate question, but I have no idea what search terms
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.