doude1917 2009-12-16 03:02
浏览 36

表格提交 - 成功

well I have a very weird Form Submission problem on which I wasted days and still cannot figure it out: 1) when I fill in the form properly (for a new user) works well 2) if I try to register a user with an existing email... it just refreshes instead of throwing an error 3) if I submit the form after a failed attempt I do not receive any success sign although data has been submitted to the database here is my code:

 $(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.
Please try another address and then submit it again!');
        }
        else if(reply ==2){ //do nothing
        //  alert('You have one or more empty fields!
Please provide all the information required and then submit it again!');
        }
        else if(reply == 0){
        $('#pForm').hide('fast');
        $('#accForm').show('slow');
        }
                              }
                });      

  });  
});  

and my php looks like this:

 <?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 + "
";}
    if ($empty == false){
        //echo ""+ $accType +"
"+ $fname +"
"+ $lname +"
"+ $email +"
"+ $country +"
"+  $state +"
"+ $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;

 ?>

Any ideas and thanks for your help!

  • 写回答

2条回答 默认 最新

  • duanjiani6826 2009-12-16 04:14
    关注

    Have you tested by implementing an error handler on the ajax call?

    On an unrelated note, you really need to use some form of data escaping/database protection with your queries, preferably with prepare.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题