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

  • Home
  • SEARCH
  • 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 7698263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:12:05+00:00 2026-05-31T22:12:05+00:00

I read similar questions to this problem but I couldn’t find out why it

  • 0

I read similar questions to this problem but I couldn’t find out why it does it here.
Basically a jquery ajax call sends some info to be submitted. The problem is that the form is submitted the first time once, then second time twice, third time 4 times. I can’t understand where is the problem. Could you please help?

$('#form10').submit(function () {
    //Get the data from all the fields
    var UserID = $('input[name=UserID]');
    var problemID = $('input[name=problemID]');
    var solution_text = $('textarea[name=solution_text]');
    var MM_insert = $('input[name=MM_insert]');

    //organize the data properly
    var data = 'UserID=' + UserID.val() + '&problemID=' + problemID.val() + '&solution_text=' + solution_text.val() + '&MM_insert=' + MM_insert.val();

    //show the loading sign
    $('.loading').show().delay(1200).fadeOut();
    //start the ajax
    $.ajax({
        //this is the php file that processes the data
        url: "/js/ajax/add-comment.php",
        //POST method is used
        type: "POST",
        //pass the data         
        data: data,
        //Do not cache the page
        cache: false,
        //success
        success: function (html) {
            //if process.php returned 1/true (success)
            if (html == 1) {
                //hide the gif
                $('.loading').fadeOut('slow');
                //show the success message
                $('#comment-success').delay(1000).slideDown('slow').delay(2000).slideUp('slow');
                $('#comments').load('/js/ajax/comments2.php?problemID=' + problemID.val());
                //if process.php returned 0/false (failed)
            } else {
                $('#error-msg2').show('slow');
            }
        }
    });
    //cancel the submit button default behaviours
    return false;
});

php back code

 .............

 if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "comments")) {
  $insertSQL = sprintf("INSERT INTO solution (UserID, solution_date, problemID, solution_text) VALUES (%s, %s, %s, %s)",
                   GetSQLValueString($UserID, "int"),
                   GetSQLValueString(date('Y-m-d H:i:s', mktime()), "text"),
                   GetSQLValueString($problemID, "int"),
                   GetSQLValueString($solution_text, "text"));

 mysql_select_db($database_tccconn, $tccconn);
  $Result1 = mysql_query($insertSQL, $tccconn) or die(mysql_error());

  if($Result1) { echo '1';}
  else
  { echo '0';}

}

the form

form method="post" action="" name="form10" id="form10">
   <input type="hidden" name="problemID" value="<?php echo $this->escape($this->item['problemID']);?>">
   <input type="hidden" name="UserID" value="<?php $identity = Zend_Auth::getInstance()->getIdentity(); ?>">  

   <textarea name="solution_text" id="solution_text" class="create" rows="6"></textarea>
   <input type="submit" name="submit" value="Reply to post" class="submit">
  <input type="hidden" name="MM_insert" value="comments">
  <div class="loading"></div>

  </form>

code frm comments2

mysql_select_db($database_tccconn, $tccconn);
$query_rstcomments = sprintf("SELECT solution.solutionID, solution.UserID, solution.solution_date, solution.solution_text,     solution.problemID, user.org_name FROM solution NATURAL JOIN user  WHERE solution.problemID = %s     ORDER BY solution.solutionID ASC", $colname_rstcomments);
$rstcomments = mysql_query($query_rstcomments, $tccconn) or die(mysql_error());
 $row_rstcomments = mysql_fetch_assoc($rstcomments);
$totalRows_rstcomments = mysql_num_rows($rstcomments);

 if($rstcomments) {

  do { ?>


<div class="comments-in-top">
      <div style="width: 166px; float: left">
       <div class="comments-in-bottom">
       Posted by<br /><strong><?php echo ucwords(stripslashes($row_rstcomments['org_name'])); ?></strong><br />On <?php  echo date("j F Y",strtotime($row_rstcomments['solution_date'])); ?><br />at <?php echo date("H:i",strtotime($row_rstcomments['solution_date'])); ?>
       </div>
    <div class="comments-in-bottom-b"></div>
      </div>
     <div class="comments-in-top-in">
       <?php echo nl2br(ucfirst(stripslashes($row_rstcomments['solution_text']))); ?>
     </div>
 </div>
<?php } while ($row_rstcomments = mysql_fetch_assoc($rstcomments));


} ?>
  • 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-05-31T22:12:06+00:00Added an answer on May 31, 2026 at 10:12 pm

    Use unbind(‘submit’) function while submitting form. This should fix it
    (no change except line number 1 in below code)

    $('#form10').unbind('submit').submit(function () {
        //Get the data from all the fields
        var UserID = $('input[name=UserID]');
        var problemID = $('input[name=problemID]');
        var solution_text = $('textarea[name=solution_text]');
        var MM_insert = $('input[name=MM_insert]');
    
        //organize the data properly
        var data = 'UserID=' + UserID.val() + '&problemID=' + problemID.val() + '&solution_text=' + solution_text.val() + '&MM_insert=' + MM_insert.val();
    
        //show the loading sign
        $('.loading').show().delay(1200).fadeOut();
        //start the ajax
        $.ajax({
            //this is the php file that processes the data
            url: "/js/ajax/add-comment.php",
            //POST method is used
            type: "POST",
            //pass the data         
            data: data,
            //Do not cache the page
            cache: false,
            //success
            success: function (html) {
                //if process.php returned 1/true (success)
                if (html == 1) {
                    //hide the gif
                    $('.loading').fadeOut('slow');
                    //show the success message
                    $('#comment-success').delay(1000).slideDown('slow').delay(2000).slideUp('slow');
                    $('#comments').load('/js/ajax/comments2.php?problemID=' + problemID.val());
                    //if process.php returned 0/false (failed)
                } else {
                    $('#error-msg2').show('slow');
                }
            }
        });
        //cancel the submit button default behaviours
        return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I read some similar questions (for example at this link ), but the problem
I've already read through the similar questions on this topic, but none of them
I've read numerous similar questions, but the answers simply didn't work. Running this function
I've read similar questions here but I'm still a little confused. MyCollection extends ArrayList<MyClass>
I read through quite a few similar questions here on SO but none were
I read through several questions similar to this one before posting, but did not
I've read a lot of similar questions, but I can't seem to find an
I realise there are a lot of similar questions, but I couldn't find any
I've read other questions with similar titles and I think this is a different
I have read similar questions but they talk of AI models. What I want

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.