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

  • Home
  • SEARCH
  • 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 6185639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:45:02+00:00 2026-05-24T01:45:02+00:00

I have the following Javascript code: function checkIfValid(){ var form = document.createuserform; if(form.fName.value ==

  • 0

I have the following Javascript code:

function checkIfValid(){
    var form = document.createuserform;

    if(form.fName.value == "" || form.lName.value == "" || form.pass.value == "" || !isValidEmail()){
    alert("Please Ensure All Fields Are Filled In Correctly");
    }else{
    //submit form
    form.submit();
    }
}

function isValidEmail(){
    var x=document.forms["createuserform"]["email"].value
    var atpos=x.indexOf("@");
    var dotpos=x.lastIndexOf(".");
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
    {
    return false;
    }
    return true;
}

This for a create user page. The javascript checks to see if the data entered is valid and then submits the form to a php app which then stores the data in the database…

Here is the HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Create User</title>
<script src="http://dev.speechlink.co.uk/David/js/createuser.js" type="text/javascript"></script>
</head>

<body>
<h1>Create User</h1>

<p>Please fill in the details below to create a new user account</p>

<form name = "createuserform" action = "http://dev.speechlink.co.uk/David/createuser.php" method = "post">
<p>First Name:&nbsp;&nbsp;&nbsp;&nbsp;<input name = "fName" type="text" size="25"></p>

<p>Last Name:&nbsp;&nbsp;&nbsp;&nbsp;<input name = "lName" type="text" size="25"></p>

<p>E-mail:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name = "email" type="text" size="25"></p>

<p>Password:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name = "pass" type="text" size="25"></p>

<p> Gender:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="gender" value="M" checked> Male
<input type="radio" name="gender" value="F"> Female</p>

<p>User Type: &nbsp;&nbsp;&nbsp;&nbsp;<select name="usertype"> 
<option>Athlete</option>
<option>Support Staff</option>
</select></p>

<p><input type ="button" value="Create Account" name = "createuser" onclick="checkIfValid()"></p>
</form>
</body>
</html>

The php code is as follows:

<?php

session_start();

$dbh = connect();

//connect to database
function connect() {
  $dbh = mysql_connect ("localhost", "abc123", "def567") or die ('I cannot connect to the database because: ' . mysql_error());
  mysql_select_db("PDS", $dbh); 
  return $dbh;
}

//insert into database
if (isset($_POST['createuser'])){

    //prevent SQL injections (this version of php does not support mysqli functions)
    $fn = mysql_real_escape_string($_POST['fName']);
    $ln = mysql_real_escape_string($_POST['lName']);
    $email = mysql_real_escape_string($_POST['email']);
    $gender = mysql_real_escape_string($_POST['gender']);
    $usertype = mysql_real_escape_string($_POST['usertype']);
    if($usertype == 'Athlete'){
      $usertype = 'Athletes';
    }else{
      $usertype = 'SupportStaff';
    }
    $pass = md5($_POST['pass']);

    if(eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)) {

        $query= "SELECT * FROM $usertype WHERE email = '" . $email . "'";
        $result = mysql_query($query);

        if(mysql_num_rows($result) < 1 || !mysql_num_rows($result)) {

            $query= "INSERT INTO $usertype (fName, lName, gender, email, password) VALUES ('$fn', '$ln', '$gender', '$email', '$pass')";
            mysql_query($query);
            mysql_close($dbh);
            echo ("&result=true&");         
        } else {
            mysql_close($dbh);
            echo "&result=userexists&";         
        }
    }
    else {
        mysql_close($dbh);
        echo "&result=false&"; //invalid e-mail address
    }   
}
?>

The php works when I use a submit button in the HTML form to POST directly to it. But when I use the javascript, the page is targeted but it is blank…nothing is echo’d…Any ideas?

I have a feeling the form is not catching the ‘createuser’ name of the HTML button firing the javascript…As my php file expects $_POST[‘createuser’] to be set…perhaps it isn’t…?

  • 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-24T01:45:02+00:00Added an answer on May 24, 2026 at 1:45 am

    As you don’t press the button with the name “createuser”, “createuser” is not part of the data sent to the server.

    So instead of checking for “createuser”, you should insert a hidden field in your form and check for this.

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

Sidebar

Related Questions

I have the following Javascript code: function checkIfValid(){ var form = document.createuserform; var valid
I have the following code in Javascript: jQuery(document).ready(function(){ var actions = new Object(); var
I have the following code: <script type=text/javascript> $(document).ready(function() { $(#Save).click(function() { $.post(url, { data:
So I have the following JavaScript code: <script type=text/javascript> function clearRadioButtons() { document.getElementById(radiobutton1).checked=; //etc
I have the following javascript code: <script type=text/javascript> $(function () { var currentDateTime =
I have the following javascript code. var Test = function(){ $(#+elementId).click(function(){ // How to
I have the following JavaScript code: var cILo=true; var img1=images/title-2a.png; var img2=images/title-2b.png; function loadblinker()
Let's say we have the following JavaScript/jQuery code below function createElement(i, value) { return
I have the following JavaScript code: Link In which the function makewindows does not
I have the following javascript code, which loads without error, however the update function

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.