以下是我的註冊表單的驗證功能。問題是如果用戶輸入所有正確的數據,如何用SQL語句觸發我的PHP函數以將其插入到我的數據庫中?傳遞Javascript結果到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;
}
}
AJAX ........... – 2013-04-30 06:02:33
@deceze喜歡在代碼中的答案,並與我的情況有關。 – rapide 2013-04-30 06:19:27
如果你有一個特定的問題,大量的人會很樂意幫助你,但就你而言,這聽起來像你錯過了整個服務器端相當於該腳本。我們不能爲你寫。 – 2013-04-30 06:23:43