title: jQuery/AJAX post() - a few problems
body: <p>I'm basically working on a site in which a user repeatedly clicks a button, increasing his score each time he clicks. I don't want the page to refresh between each click, so I'm using AJAX. </p>
  
  <p>The problems I'm having currently are as follows:</p>
  
  <ol>
  <li><p>When I try to set my javascript <code>var</code> to <code>=</code> <code>&lt;? echo $result['count']; ?&gt;</code>, it doesn't seem to work.</p></li>
  <li><p>I don't understand how to correctly use PDO to <code>UPDATE</code> a MySQL table with a calculation in the query, such as <code>$update = $dbh-&gt;execute("UPDATE count SET count='$count'+1 WHERE username='$username'");</code>. Is this the correct syntax for the calculation and is this the right way to do it in PDO?</p></li>
  </ol>
  
  <p>Here is the code for my testing page which I am using for the clicking system:</p>
  
  <pre><code>&lt;html&gt;
  &lt;?php 
  
  $hostname = 'localhost';
  $username2 = 'refrigerator';
  $password = 'xxx';
  
  $dbh = new PDO("mysql:host=$hostname;dbname=refrigerator", $username2, $password);
  $username = $_COOKIE["user"];
  
  $rows = $dbh-&gt;prepare("SELECT count FROM count WHERE username = '$username'");
              $rows-&gt;execute();   
              $result = $rows-&gt;fetchALL();
              $result['count'] = $count;  
  
  if(isset($_POST['action'])){    
  
      if ($_POST['action'] == 'increase'){
  
          $update = $dbh-&gt;execute("UPDATE count SET count='$count'+1 WHERE username='$username'");            
      }
  }
  ?&gt;
  &lt;body&gt;
  &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.4.3.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function(){
  
      var count = &lt;? echo $result['count']; ?&gt;;
  
          $("#update").click(function() {
              $.ajax({
              type: "POST",
              url: "button.php",
              data: {"action":"increase"},
              success: function(update) {
  
                  count++;
                  $("#counter").html(+count);
              }
          });
      });
  });
  &lt;/script&gt;
  &lt;button id="update" type="button"&gt;Button&lt;/button&gt;
  &lt;div id="counter"&gt;&lt;? echo $result['count']; ?&gt;&lt;/div&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Thanks a lot, any help would be greatly appreciated. Even if you can point me in the right direction which will help me answer my questions, that would be awesome. </p>
  
  <p>Thank you</p>