Jump to content

[SOLVED] Hit Counter - Please Help


jandrews

Recommended Posts

Hey guys, this can easily sound more complicated than it is, so I'l try to keep it simple.

 

Im building a site that uses dynamic data from a Mysql database and I want the 'hit' column in my existing database table to increment by 1 when a row is queried.

 

Here is my code ( I know all the connections stuff isn't there because they are in a different file which is being included on the same page)

 

 

<?php

    $select = mysql_query("UPDATE `example_table` `SET `hits` = `hits`+1 WHERE title_music='['track']'");

?>

 

As you might expect, it doesnt work.

 

The '['track']' in the code is the url variable.

 

Am I barking up the wrong tree? or is there a better way of doing this?

Link to comment
https://forums.phpfreaks.com/topic/153523-solved-hit-counter-please-help/
Share on other sites

Try this:

 

    $select = mysql_query("UPDATE example_table SET hits = hits+1 WHERE title_music='{$_GET['track']}'") or die(mysql_error());

 

NOTE: You don't need all those backticks.  The only time you need them is when you're using reserved MySQL words.  You can also escape the single quotes from your GET, which is how you retrieve variables from the URL, with { and }.

Archived

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.