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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:43:25+00:00 2026-06-16T15:43:25+00:00

I want to perform an insert into the database so that the database table

  • 0

I want to perform an insert into the database so that the database table Individual Answer contains the following data:

Individual_Answer Table:

AnswerId  AnswerMarks
295       2
296       1
297       1
298       3
299       3

Problem is that it is not inserting into database. Is it the php/mysqli code which is causing the problem or is it the ajax that is not accessing the php page which is doing the insert (insertmarks.php)?

Below in my code in php/mysqli:

<?php

 // connect to the database
 include('connect.php');

  /* check connection */
  if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    die();
  }

var_dump($_POST);  

 $answersql = "INSERT INTO Individual_Answer (AnswerId, AnswerMarks) 
    VALUES (?, ?)";

if (!$insertanswer = $mysqli->prepare($answersql)) {
    // Handle errors with prepare operation here
    echo __LINE__.': '.$mysqli->error;
}



//make sure both prepared statements succeeded before proceeding
if($insertanswer)
{
   $c = count($_POST['answerId']);

    for($i = 0;  $i < $c; $i++ )
    {


$insertanswer->bind_param('ii', $_POST['answersId'][$i], $_POST['answerMarks'][$i]);

}
    //close your statements at the end

    $insertanswer->close();
}

?>

Below is the var_dump($_POST) outputting:

array(7) { 
["q1_ans_org"]=> string(1) "4" 
["q1_ans"]=> string(1) "0" 
["answerMarks"]=> array(5) 
{ 
[0]=> string(1) "2" 
[1]=> string(1) "1" 
[2]=> string(1) "1" 
[3]=> string(1) "3" 
[4]=> string(1) "3" } 
["q2_ans_org"]=> string(1) "6" 
["q2_ans"]=> string(1) "0" 
["num_groups"]=> string(1) "2" 
["submitMarks"]=> string(12) "Submit Marks" 
} 

Below is the html and jquery/ajax code which is suppose to access insertmarks.php:

<form id="Marks" action="penalty.php" method="post">

...

<p>
<input type='hidden' id='num_groups' name='num_groups' value='<?php echo$questionId?>'>
<input id="submitBtn" name="submitMarks" type="submit" value="Submit Marks" />
</p>

</form>

...

<script type="text/javascript">

myClickHandler = function(e) {
       var ng = $('#num_groups').val();
       for (var group = 1; group <= ng; group++) {
         if (!validation(group)) return false;
       }
       if (confirm("Make sure that your marks are correct, once you proceed after this stage you would not be able to go back and change any of your marks for this Assessment." + "\n" + "\n" + "Are you sure you want to Proceed?" + "\n")) {
         $.ajax({
           url: "insertmarks.php",
           data: $("#Marks").serialize(),
           async: false,
           type: "POST"
         });
         return true;
      } else {
        return false;
      }
    };

    $('#Marks').submit(myClickHandler);

});

</script>
  • 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-16T15:43:27+00:00Added an answer on June 16, 2026 at 3:43 pm

    You didn’t execute the query,

    $insertanswer->execute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to insert data into Image_Question Table. but it does not perform an
I have roughly 100,000 Objects that I want to insert into the database. I
I have to insert data into a table with the following pattern INSERT INTO
I'm trying to perform an INSERT INTO statement like the following: insert into table1
I want to send (INSERT) a doc file, e.g resume into a table of
I want to insert n records into a single table. There may be many
I want to write a service (probably in c#) that monitors a database table.
I want to use a single query to insert into a table and if
I have some collection and I want to perform action on every insert into
I'm using the MySQL statement INSERT INTO to insert data into my table. I

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.