user652792
user652792

Reputation:

How to do a Vote Up for a Comment

I'm trying to do a like button (Not Facebook), just an Up Vote functionality in the comments of my article for my website. I've placed each like button inside the while loop that echo out the comments so that each like button image appears in each comments box, with this part of my code

           if(isset($_SESSION['username'])) { 
 echo"<a href=\"\"><input type=\"image\"name=\"like\"src=\"like.jpeg\"></a>";
    }

And i'm trying to check if the button is clicked, with this code, if yes, it should insert the specified values into the likes table.

         if(isset($_POST['like'])) {

   $query1   = "INSERT INTO likes (
                likes_id, user_id, 
                comment_id, total_likes)  
                VALUES (NULL,'".$_SESSION['logged_username']."', '".$_SESSION['article_id']."', $page_name+1)";
                mysql_query($query1) or die mysql_error());

but the code is not working at all.

No error is showing and nothing is inserted into the likes table.

Please how can I make this work/where is the problem coming from? What might be a better solution if this is not do-able?

Please forgive my code formatting, i meant no disrespect to this community.

Thank you.

Upvotes: 1

Views: 243

Answers (2)

Mark Byers
Mark Byers

Reputation: 838696

You have a parenthesis where there shouldn't be one:

mysql_query($query1));
                    ^

Upvotes: 3

Bryan
Bryan

Reputation: 6752

To figure out what the actual error is, do this.

mysql_query($query1) or die(mysql_error());

Upvotes: 0

Related Questions