开发者

Form Submission- success

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.\nPlease try another address and t开发者_JAVA技巧hen 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');
        }
                              }
                });      

  });  
});  

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 + "\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;

 ?>

Any ideas and thanks for your help!


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.


if(reply ==1){
    alert('Email address already exists in our members database.\nPlease try another address and then submit it again!');
    return false;
}

Try this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜