-1

Below is my validation function of my registration form. Problem is if the user input all the correct data, how to I trigger my php function with SQL statement to insert it into my database?

<script type="text/javascript">
function validate(){
var school_name = document.formValidation.school_name.value;
var mailing_address = document.formValidation.mailing_address.value;
var city = document.formValidation.city.value;
var state = document.formValidation.state.value;
var postcode = document.getElementById('postcode');
var courier_address = document.formValidation.courier_address.value;
var courier_city = document.formValidation.courier_city.value;
var courier_state = document.formValidation.courier_state.value;
var courier_postcode = document.getElementById('courier_postcode');
var phonenumber = document.getElementById('phonenumber');
var faxnumber = document.getElementById('faxnumber');
var email = document.getElementById('email');
var website = document.formValidation.website.value;

var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

if(school_name == "" || mailing_address == "" || city == "" || state == "" || postcode == "" || courier_address == "" || courier_city == "" || courier_state == "" || courier_postcode == "" || phonenumber == "" || faxnumber == "" || email == "" || website == ""){
    alert("Please enter fields marked with an asterisk");
    return false;
} 
if (!/^[0-9]+$/.test(postcode.value)) { 
    alert("Please enter numbers only for postcode");
    postcode.value = postcode.value.substring(0,postcode.value.length-1);
    return false;
    }
if (!/^[0-9]+$/.test(courier_postcode.value)) { 
    alert("Please enter numbers only for courier postcode");
    courier_postcode.value = courier_postcode.value.substring(0,courier_postcode.value.length-1);
    return false;
    }
if (!filter.test(email.value)) {
    alert("Please enter a valid email address");
    email.focus;
    return false;
}
    else {
    alert("Registration Success!");
    <?php


    ?>
    return true;
}

}

rapide
  • 25
  • 4
  • @deceze Prefer the answer to be in codes and related to my situation. – rapide Apr 30 '13 at 06:19
  • 1
    If you have a specific problem, loads of people will be happy to help you, but in your case, it sounds like you're missing the whole server-side equivalent of that script. We can't write that for you. – Tasos Bitsios Apr 30 '13 at 06:23

2 Answers2

1

Javascript runs on the users' browsers. PHP runs on your server. You have to send that data to the server, validate it there as well, then insert into the database.

Tasos Bitsios
  • 2,699
  • 1
  • 16
  • 22
0

Next you need a POST or GET action to send the variables to your PHP script on the serverside (this JavaScript is executed on the clientside). JQuery offers some real good and handy functions for that: .post() and .get().

http://api.jquery.com/jQuery.post/ and http://api.jquery.com/jQuery.get/

Borniet
  • 3,544
  • 4
  • 24
  • 33