以下是我的注册表单的验证功能。问题是如果用户输入了所有正确的数据,我如何用 SQL 语句触发我的 php 函数将其插入到我的数据库中?
<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;
}
}