Jump to content

Getting errors on code I have used before (Page view count)


Recommended Posts

Hey everyone,


So here is my problem. I have some code to display the amount of views that page has got. In this case it is the thread in my forums section. I have used the same code to show how many people have views a certain persons profile page and that works fine but when I use it on my forum thread page I get this error.


You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id='20' LIMIT 1' at line 1


Here is the section of code:


$thread_id = preg_replace('#[^0-9]#i', '', $_GET['id']);
$getThreadViews = mysql_query("SELECT view_count FROM forum_posts WHERE id='$thread_id' LIMIT 1") or die (mysql_error());
$row = mysql_fetch_assoc($getThreadViews);
$counter = $row['view_count'];

if($counter == 0){
$counter = 1;
$startCounter = mysql_query("INSERT INTO forum_posts (view_count) VALUES ('$counter') WHERE id='$thread_id' LIMIT 1") or die (mysql_error());

$threadViews = $counter+1;
$appendCounter = mysql_query("UPDATE forum_posts SET view_count='$view_count' WHERE id='$thread_id'") or die (mysql_error());



I have checked that there are no spelling errors so just wanted to show it to a fresh pair of eyes because its really starting to annoy me.


Thanks in advance for any help.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.