Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8941713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:22:10+00:00 2026-06-15T11:22:10+00:00

m having a problem while submitting the form using jquery & Ajax. my prob

  • 0

m having a problem while submitting the form using jquery & Ajax. my prob is that i want to insert some values into the database before submitting the form. code that i am using is as below for form submission :

$('.buttons').click(function(){

var account_num = $("#accountNum").val();
var ref_num = $("#refNum").val();

var dataString = "account_num="+ escape(account_num) + "&reference_no=" + escape(ref_num);

$("#frmTransaction").hide();
$("#loader_div").show();

$.ajax({
   type : "Post",
   url  : "validate-data.php",
   data : dataString,
   success: function(html) {
      if(html) {
    alert(html);
    $("#frmTransaction").submit();

      } else {
          alert('Unknown Error Please...Retry');    
       return false;
       }
    }, error :function (){
        return false    
    }, 
       complete: function () {  }

});
 return false;

});

html form is as :

<form  method="post" action="https://sample.com/pay" name="frmTransaction" id="frmTransaction">
<input name="accountNum" id="accountNum" type="hidden" size="60" value="<? echo $_POST['account_id'] ?>">
<input name="refNum" id="refNum" type="hidden" size="60" value="<? echo $reference_no;?>" />
<input type="text" class="field" name="name" id="name" />
<input type="text" class="field" name="city" id="city" />
<input type="text" class="field" name="state" id="state" />
<input type="text" class="field" name="postal_code" id="postal_code" />
<input type="submit" class="buttons" name="submitted" value="Proceed" />
</form>

content of validate-data.php is as :

<?PHP
        $account_num = $_REQUEST['account_num'];
    $reference_no = $_REQUEST['reference_no'];

    $countF = mysql_num_rows(mysql_query("SELECT * FROM orders where order_id='".$reference_no."'"));

    if($countF == 0 ) {
        $res = mysql_query("insert into orders(order_id, user_account_num)values('".$reference_no."', '".$account_num."')");
    } 

if($res) 
    echo "$res ";
else 
    echo "";    
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T11:22:11+00:00Added an answer on June 15, 2026 at 11:22 am

    only two problem :
    One, see your callback success:

    success: function(html) {
      if(html) {
      alert(html);
      $("#frmTransaction").submit();
    
      } else {
          alert('Unknown Error Please...Retry');    
       return false;
       }
    }
    

    your if statement will ask to computer, if isset variable html
    and two, you print the mysql query on your php code …

    if($res) 
       echo "$res ";
    else 
       echo "";
    

    and the workaround:
    change your jquery code with this one:

    $.ajax({
     type : "Post",
     url  : "validate-data.php",
     data : dataString,
     success: function(html) {
     var callback = $.parseJSON(html); // Parse your callback
       if(callback.process == 'success'){
          $("#frmTransaction").submit();
       } else {
          alert('Unknown Error Please...Retry');    
       }
     }, error:function(){
        alert('Unknown Error Please...Retry');    
     }, 
    });
    

    and the php code:

    <?PHP
     $account_num = mysql_real_escape_string($_POST['account_num']); // make sure `$_POST` and `mysql_real_escape_string` used to prevent sql injection
     $reference_no = mysql_real_escape_string($_POST['reference_no']); // And this line too
    
     $countF = mysql_num_rows(mysql_query("SELECT * FROM orders where   order_id='".$reference_no."'"));
    
    if($countF == 0 ) {
        $res = mysql_query("insert into orders(order_id,   user_account_num)values('".$reference_no."', '".$account_num."')");
    } 
    
    if($res){
      echo json_encode(Array("process" => "success"));
    }
    else {
      echo json_encode(Array("process" => "fail")); 
    }
    ?>
    

    Good luck, Friend

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm having a problem while encrypting some data in the file. i'm using simple
I'm having an odd problem while deploying a Django site using Fabric. I've configured
While trying to troubleshoot a problem I'm having with a project, I noticed that
I am having a problem while doing some XSLT pre-processing in my java program.
In Java development using Spring 3.0, I am having problem while executing the Sproc
I'm having a problem while using constructors with a Groovy class. I have a
I'm having a strange problem while using NSDictionnary ... I'm trying to retrieve an
The problem I am having is that my jquery script is not returning the
I am having a problem while calling overloaded C# function through jquery post method.
I'm having a problem while trying to make my own chess game using JLayeredPane

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.