Jump to content

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 }.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.