-1

以下是我的注册表单的验证功能。问题是如果用户输入了所有正确的数据,我如何用 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;
}

}

4

2 回答 2

1

Javascript 在用户的浏览器上运行。PHP 在您的服务器上运行。您必须将该数据发送到服务器,在那里进行验证,然后插入数据库。

于 2013-04-30T06:04:10.203 回答
0

接下来,您需要一个 POST 或 GET 操作将变量发送到服务器端的 PHP 脚本(此 JavaScript 在客户端执行)。JQuery 为此提供了一些非常好的和方便的函数:.post() 和 .get()。

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

于 2013-04-30T06:03:41.160 回答