jandrews Posted April 10, 2009 Share Posted April 10, 2009 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 More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 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 }. Link to comment https://forums.phpfreaks.com/topic/153523-solved-hit-counter-please-help/#findComment-806652 Share on other sites More sharing options...
jandrews Posted April 10, 2009 Author Share Posted April 10, 2009 Thank you very much that works, Here is the code i used: <?php $select = mysql_query("UPDATE`example_table` SET `hits` = `hits`+1 WHERE title_music='{$_GET['track']}'") or die(mysql_error()); ?> :) :) Link to comment https://forums.phpfreaks.com/topic/153523-solved-hit-counter-please-help/#findComment-806660 Share on other sites More sharing options...
Maq Posted April 10, 2009 Share Posted April 10, 2009 You can use backticks if you want, it won't hurt, it just makes things messy when you have them, single quotes and double quotes. Link to comment https://forums.phpfreaks.com/topic/153523-solved-hit-counter-please-help/#findComment-806663 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.