title: Insert into database using onclick function
body: <p>I'm developing a kind of question search engine based on Course wise, Subject wise by entering the keyword or question. 
  Here I am querying the database based on search term against 3 tables namely <code>table_one</code>, <code>table_two</code>, and <code>table_three</code>. Code as follows </p>
  
  <pre><code>&lt;?php
   if(isset($_GET['submit']))
   {
     $query = $_GET['query'];
     $query = htmlspecialchars($query);
     $query = mysqli_escape_string($link,$query);
     $searchTerms = explode(' ', $query);
     $searchTermBits = array();
     foreach ($searchTerms as $term) {
      $term = trim($term);
      if (!empty($term)) {
          $searchTermBits[] = "question LIKE '%$term%'";
      }
    }
  
   $subject_id = $_GET['subject'];
   $course_id = $_GET['course'];
   $min_length = 1;
   if(strlen($query) &gt;= $min_length)
   {
  
    $res = "SELECT id,course_id,subject_id,question,option_a,option_b,option_c,option_d,option_e,correct_ans,fmge_year,contributor FROM table_one
  WHERE (".implode(' OR ', $searchTermBits).") AND (`subject_id` LIKE '%".$subject_id."%') AND (`course_id` LIKE '%".$course_id."%')
  UNION ALL
  SELECT id,course_id,subject_id,question,option_a,option_b,option_c,option_d,option_e,correct_ans,fmge_year,contributor FROM table_two 
  WHERE (".implode(' OR ', $searchTermBits).") AND (`subject_id` LIKE '%".$subject_id."%') AND (`course_id` LIKE '%".$course_id."%')
  UNION ALL
  SELECT id,course_id,subject_id,question,option_a,option_b,option_c,option_d,option_e,correct_ans,fmge_year,contributor FROM table_three 
  WHERE (".implode(' OR ', $searchTermBits).") AND (`subject_id` LIKE '%".$subject_id."%') AND (`course_id` LIKE '%".$course_id."%')";
  
  $raw_results = mysqli_query($link,$res) or die (mysqli_error());
  if(mysqli_num_rows($raw_results) &gt; 0)   
  {
  echo "&lt;h3 style='text-align:center;color:#3366CC'&gt;&lt;span style='color:#000000'&gt;Search Results For : &lt;/span&gt; $query &lt;/h3&gt;";
  while($results = mysqli_fetch_array($raw_results))
  {
  echo "&lt;div class='content'&gt;";
  echo"&lt;h4 id=".$results['id']."&gt;" .preg_replace("/".preg_quote($query, "/")."/i", "&lt;span class=\"highlight\"&gt;$query&lt;/span&gt;", $results['question']) . "&lt;/h4&gt;";
  echo"&lt;p id=".$results['id']."&gt;&lt;span style='padding-left:20px'&gt;option A : " .$results['option_a']."&lt;/span&gt; &lt;br&gt;&lt;span style='padding-left:20px'&gt; option B : ".$results['option_b']."&lt;/span&gt;&lt;br/&gt;&lt;span style='padding-left:20px'&gt;option C : ".$results['option_c'].
  "&lt;/span&gt;&lt;br&gt;&lt;span style='padding-left:20px'&gt;option D : ".$results['option_d']."&lt;/span&gt;&lt;br&gt;&lt;span style='padding-left:20px'&gt; option E : ".$results['option_e']."&lt;/span&gt;&lt;br&gt;&lt;span style='color:#253E66;font-weight:bold;padding-left:20px'&gt;Correct Ans : ".$results['correct_ans']. 
  "&lt;/span&gt;&lt;br&gt;&lt;span style='padding-left:20px'&gt;Question Year : ".$results['question_year']."&lt;/span&gt;&lt;br&gt;&lt;span style='padding-left:20px'&gt;Contributor : ".$results['contributor']."&lt;/span&gt;&lt;br /&gt;
  &lt;a onclick=addQuestion('".$results['id']."') href='#'&gt;&lt;span class='button'&gt;Add to Question Bank&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;";
  echo "&lt;/div&gt;";
  }
  }
  else{
  
  echo "&lt;span style='height:21px;syle=background-color: #F1F0FF;font-size:25px;color:#CC0000'&gt;Your search - $query - did not match any queries.&lt;/span&gt; ";
  }
  }
  }
  ?&gt;
  </code></pre>
  
  <p>I'm Calling the following addQuestion() function when i click the Add to Question Bank link.</p>
  
  <pre><code>    &lt;script&gt;
      function addQuestion(val)
      {
          var conf=confirm("Are you sure you want to add this question to Question Bank")
  
          if(conf){
               //Here I Want some code to update my database. 
                }
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>The script above displaying confirmation box when i click the button, 
  My Question is,
  After confirmation I want to insert my question into the new table in the database and display message like "Question added" in front of the question permanently  as i know i can't write PHP inside Jquery function Any help may appreciated.      </p>