Can't seem to get my like/dislike to work in PHP
<p>My table is comment_likedislike. It has the comment_counterid, comment_counter, comment_id(which is from another table) fields. 
And I have an url (LIKE) that when clicked would link to this code and get the comment_id and like_id.</p>

<p>I want to do a count where if it is the first 'like', it would store a new comment_counter in the comment_likedislike table. But if there is already a 'like' for the comment in the table, it would just update the comment_counter to +1. </p>

<p><strong>Problem:</strong> When I run this code, it doesn't UPDATE(1st statement) but INSERT(2nd if statement) no matter if there is a like for the comment or not. I don't think the code is checking if the comment_id is in the table already. </p>

<p>I am a novice php programmer. </p>

<p>Thanks!</p>

<pre><code>if (isset($_GET['comment_id']) &amp;&amp; isset($_GET['like_id'])) {
    $query5="SELECT * FROM comment_likedislike ";
    $data5=mysqli_query ($dbc, $query5);
    while ($row5= mysqli_fetch_array($data5)){
        $comment_id2=$row5['comment_id'];   
    }

        if ($comment_id2 == $_GET['comment_id']){

            $counter=$row5['comment_counter'];
            $counter++;

            $query= "UPDATE comment_likedislike SET comment_counter ='$counter' WHERE comment_id= '".$_GET['comment_id']."' ";
            mysqli_query($dbc, $query);

        }
        if ($comment_id2 != $_GET['comment_id']) {
            $counter2=1;
            $query9 = "INSERT INTO comment_likedislike (comment_counter, comment_id) VALUES ('$counter2', '".$_GET['comment_id']."' )";
            mysqli_query($dbc, $query9);
        }

}
</code></pre>
