好吧,我有一个非常奇怪的表单提交问题,我浪费了几天,仍然无法弄清楚: 1)当我正确填写表格时(对于新用户)效果很好 2)if我尝试使用现有电子邮件注册用户...它只是刷新而不是抛出错误 3)如果我在尝试失败后提交表单,我没有收到任何成功标志,尽管数据已提交到数据库 此处是我的代码:表格提交 - 成功
$(function() {
$("#send").click(function() {
// validate and process form here
//var email = $("#email").val();
//var lname = $("input#lname").val();
var dataString = $("#pForm").serialize();
//alert (dataString);
$.ajax({
type: "POST",
url: "../php/insertUser.php",
data: dataString,
success:function(msg, status){
//alert (dataString);
var reply = parseInt(msg);
alert(status+ "" + msg);
if(reply ==1){
alert('Email address already exists in our members database.\nPlease try another address and then submit it again!');
}
else if(reply ==2){ //do nothing
// alert('You have one or more empty fields!\nPlease provide all the information required and then submit it again!');
}
else if(reply == 0){
$('#pForm').hide('fast');
$('#accForm').show('slow');
}
}
});
});
});
和我的PHP是这样的:
<?php
include ('databaseCon.php');
$err = 0;
//echo $data= $_POST['dataString'];
$accType = $_POST['accType'];
$fname =$_POST['fname'];
$lname = $_POST['lname'];
$email = $_POST['email'];
$country = $_POST['country'];
$state = $_POST['state'];
$city = $_POST['city'];
// check for empty fields
if (($accType == "") || ($fname == "") || ($lname == "") || ($email == "") || ($country == "") || ($city == "")){
$empty = true;
}
if ($email != ""){
$em = mysql_query("Select Email from Users where Email = '$email';") or die(mysql_error());
$row = mysql_num_rows($em);
}
//else{echo "unknown error 2 " + $email + "\n";}
if ($empty == false){
//echo ""+ $accType +"\n"+ $fname +"\n"+ $lname +"\n"+ $email +"\n"+ $country +"\n"+ $state +"\n"+ $city + "" ;
if($row == 0){
echo $users = mysql_query("Insert into Users values('','$fname', '$lname', '$email', '$accType', '$country', '$state', '$city');") or die(mysql_error());
}
else{
$err = 1;}
}
else{
$err = 2;
}
echo $err;
?>
任何想法和感谢您的帮助!
检查您的HTML并查看提交按钮是否确实在
尝试使用类似Firebug的Firefox扩展,然后您可以看到您的发布数据和响应是否处于有效格式。它将帮助您识别问题 – 2009-12-16 06:20:04