title: Update database with html link click using ajax php mysql
body: <p>I've read through a number of similar questions and tried my hand at putting it to work on my website, but it is not working (when you click the link there is no response on the console and the database is not updated).</p>
  
  <p>Here's what I want to do: I want users to rate a comment <code>+1</code> by clicking an icon next to the comment. I want that to update my mysql <code>comment_table</code> column called <code>rating</code> with <code>rating+1</code>. When I do it without AJAX (ie, just set the form action to a <code>php page?id=10</code>) it works fine. I can't get the AJAX to update the database though.</p>
  
  <p>My main page with the comment:</p>
  
  <pre><code>&lt;a href="javascript:void(0);" onClick="updateRating(1,&lt;?php echo $thisperspective_row['id']; ?&gt;)" alt="UPVOTE" id="upvote_&lt;?php echo $thisperspective_row['id']; ?&gt;"&gt;&lt;span class="glyphicon glyphicon-chevron-up"&gt;&lt;/span&gt;&lt;/a&gt;
  </code></pre>
  
  <p>The javascript below that link: </p>
  
  <pre><code>&lt;script type="text/javascript"&gt; 
  function updateRating(rating, id){
  
  $.ajax({
      type: "GET",
      url: "rating.php",
      mode: "vote",
      rating: rating,
      id: &lt;?php echo $thisperspective_row['id']; ?&gt;,
      success: function(response) {
       console.log(response); 
      }
  });
  return false; // Prevent the browser from navigating to the-script.php
                  };
  &lt;/script&gt;
  </code></pre>
  
  <p>and my rating.php file is</p>
  
  <pre><code>&lt;?php
  require_once('connectiontodatabase.php'); 
  
  /* simple comment up and down voting script */
  $mode = $_GET['mode'];
  $rating = $_GET['rating'];
  $id = $_GET['id'];
  
  if ($mode=="vote")
      {
      // The name of the 
      $cookie = "nameofmycookie".$id;  
      if(isset($_COOKIE[$cookie])) 
          { 
          echo '&lt;div class="alert alert-warning"&gt;&lt;button type="button" class="close" data-dismiss="alert" aria-hidden="true"&gt;×&lt;/button&gt; Sorry You have already rated this comment within the last 14 days.&lt;/div&gt;'; 
          } 
      else 
          {
          $expiry = 1209600 + time();  // 14 day expiry
          setcookie ($cookie, "voted", $expiry);
          mysql_query ("UPDATE comment_table SET rating = rating+$rating WHERE id=$id", $connection);
          }
      }
  
  ?&gt;
  </code></pre>
  
  <p>The php runs fine and all the variables are listed properly when I view the source. However, when I click the link, there is no response at all and the console does not output the response. What am I doing wrong? Thanks in advance!</p>