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 7729849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:04:28+00:00 2026-06-01T06:04:28+00:00

I want to INSERT VALUES after user has clicked OK on the confirmation box.

  • 0

I want to INSERT VALUES after user has clicked OK on the confirmation box. Now the confirmation box works well. The only problem I can see is that when the user clicks ‘OK’ I want the INSERT VALUES to happen on a seperate page (insertQuestion.php) but I do not want the form to be navigated to that page. I want the form to navigate the way it is doing which is either submit to its own page or submit to create_session2.php depending on the situation.

So how can I INSERT VALUES into the database without navigating the user to that page (insertquestion.php) after the user has clicked ‘OK’ in the confirmation box?

I have tried using Jquery to perform an AJAX request but this has failed (Code of Jquery is at the bottom)

below is the javascript code where the confirmation box appears and if confirmation is ‘OK’, it submits the form:

 function showConfirm(){

             var confirmMsg=confirm("Do you want to Proceed" + "\n" );

             if (confirmMsg==true)
             {
             submitform();   
         }
    }

 function submitform()
            {

        var QandAO = document.getElementById("QandA");

          QandAO.submit();

            }

Below is the INSERT VALUES code (already connected to DB and is on insertQuestion.php page wile the values posted are from the previous page):

       $insertquestion = array();

      {
        $insertquestion[] = "' ". mysql_real_escape_string( $_POST['id'] ) . "', ' ". mysql_real_escape_string( $_POST['qid'] ) . "'";
      }

      $questionsql = "INSERT INTO Question (SessionId, QuestionId) 
      VALUES (" . implode('), (', $insertquestion) . ")";

mysql_query($questionsql);

Now Below is the php and form tag where the values which are going to be inserted come from:

  function insertQuestion(form) {

        var $tbody = $('#qandatbl > tbody'); 
    var $tr = $("<tr class='optionAndAnswer' align='center'></tr>");
    var $qid = $("<td name='qid' class='qid'>" + qnum + "</td>"); 
    //I am trying to insert the $qid above in the INSERT VALUES

    }

    </script>

    <form id="QandA" action="<?php echo htmlentities($action); ?>" method="post" >

<h1>CREATING QUESTIONS AND ANSWERS: SESSION (<?php echo $_SESSION['id'] ?>) 
//I am trying to insert the $_SESSION['id'] above in the INSERT VALUES

<table id="qandatbl" align="center">
<thead>
<tr>
    <th class="qid">Question No</th>
</tr>
</thead>
<tbody>//the $qid would go here</tbody>
</table>

<p><input id="submitBtn" name="submitDetails" type="submit" value="Submit Details" onClick="myClickHandler(); return false;" /></p>

</form>
  • 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-01T06:04:29+00:00Added an answer on June 1, 2026 at 6:04 am

    In your insertQuestion.php, After executing your mySQL query, Return a response back to the client. Some thing like this

    mysql_query($questionsql);
    echo "Added";
    

    So in your post call, the data variable will get that value once the jQuery post call make a call to the inert.php file

    Assuming your submit button id is submitBtn

    $("#submitBtn").click(function() {
    
        var fieldvalue = $("#QandA").val();
        $.post("insertQuestion.php", {  field1: fieldvalue} ,function(data){
           //data variable now has the reponse from the ajax call
          alert(data);
        });
      return false;  // preventing the typical form submit
    });
    

    If you are calling the above javascript in a submit button click, you should do a return false at the end, otherwise it will go for the normal form submitting and you will not be able to notice that it did an ajax post.

    EDIT : As per the question update

    Remove the onclick event of the submit button as you are already binding it in your javascipt

    <input id="submitBtn" name="submitDetails" type="submit" value="Submit Details" />
    

    in your javascript (in button click), you are calling the val() function on the form. You will not get the form content by that. What are you trying to send to the insertQuestion.php page, Is that a textbox value ? then read that specifically like this

     var fieldValue=$("#txtAnswer").val();
    

    Assuming you have a text box with an id “txtAnswer” like this in your page

    <inpuy type="text" id="txtAnswer" />
    

    If you want to send the entire form , you may use serialize function

       $.post("insertQuestion.php", $("#QandA").serialize ,function(data){
           //now you posted the entire form to insertQuestion.php
          alert(data);
        });
    

    http://api.jquery.com/serialize/

    Use firebug to see what data you are sending in the $.post call(net tab) and if there is any script errors in the page (console tab)

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

Sidebar

Related Questions

I want to insert row for each day to add new values, and I
I want to replace and insert escape character sequences with their escape character values,
I want to do something like this INSERT INTO t (t.a, t.b, t.c) VALUES
Using VB.Net I want to get a all datagrid cell values, then insert into
I execute an INSERT INTO statement cursor.execute(INSERT INTO mytable(height) VALUES(%s),(height)) and I want to
I want to insert something into a STL list in C++, but I only
I want to insert the following as the value for a variable in some
In a method, I want to be able to insert a value into a
I want to insert say 50,000 records into sql server database 2000 at a
Summary: web page has a few fields to allow the user to enter payments.

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.