Implementing a like/dislike counter with php and jquery
<p>I have a comics website, and I'd like to keep track of how many people click like and dislike for a single comic id... I'd like to store the value in my database, and also report it back out to the browser.</p>

<p>This is my non-working solution:</p>

<p><strong>viewcomic.php:</strong></p>

<pre><code>    &lt;script type="text/javascript"&gt;
    function likeCounter(choice) {    
       var site = $("#site").val();
       var imgid = $("#imgid").val();
       $.get("./scripts/likecounter.php", {_choice : choice, _site : site, _id : imgid},
            function(returned_data) {
                $("#choice").html(returned_data);
            }
        );
}
&lt;/script&gt;
       //Changed to try and work with buttons
   &lt;button id="like" onClick="likeCounter(this.id)"&gt;Like&lt;/button&gt;
   &lt;button id="dislike" onClick="likeCounter(this.id)"&gt;Dislike&lt;/button&gt;
   &lt;input id="site" type="hidden" value="&lt;?php echo $site; ?&gt;"&gt;
   &lt;input id="imgid" type="hidden" value="&lt;?php echo $imgid; ?&gt;"&gt;

&lt;br /&gt;
Likes: &lt;span id="choice"&gt;&lt;/span&gt;
</code></pre>

<p><strong>likecounter.php</strong></p>

<pre><code>&lt;?php 
include 'dbconnect.php';

$site = $_GET['_site'];
$imgid = $_GET['_id'];
$input = $_GET['_choice'];

if ($site == "artwork") {
   $table = "comics";
}
else {
   $table = "artwork";
}

$likes = $mysqli-&gt;query("SELECT like FROM $table WHERE id = $imgid");
$dislikes = $mysqli-&gt;query("SELECT dislike FROM $table WHERE id = $imgid");


if ($input == "like") {
   $sql = "UPDATE $table SET like = like + 1 WHERE id = $imgid";
   $mysqli-&gt;query($sql);
   $likes++;

else if ($input == "dislike") {
   $sql = "UPDATE $table SET like = dislike + 1 WHERE id = $imgid";
   $mysqli-&gt;query($sql);
   $dislikes++;
}   
mysqli_close($mysqli);

echo "Likes: " . $likes . ", Dislikes: " . $dislikes;

?&gt;
</code></pre>

<p>It's not incrementing the database value, and it's not reporting out a value to the browser. Any suggestions?</p>

<p>Thanks!</p>
