teknospr Posted March 7, 2011 Share Posted March 7, 2011 Good day: Im trying to add a number every time a person visits the page. here is the code Im using. Any help will be appreciated. <?php $aid = $_GET['aid']; $connection = mysql_connect("localhost", "username", "password"); mysql_select_db("articles", $connection); $query="SELECT visits FROM articles_description WHERE id=$aid"; $result=mysql_query($query); $num=mysql_numrows($result); <?php while ($j < $num) { $visits = $num[0] + 1; } $query = "UPDATE articles_description SET visits = $visits WHERE id = $aid"; if(mysql_query($sql_query)) { echo "Record updated successfully"; $j++; } mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 7, 2011 Share Posted March 7, 2011 SET visits = $visits+1 udates a table plus 1 via there id. Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 7, 2011 Share Posted March 7, 2011 SET visits = $visits+1 You wouldn't use a variable $visits - just the field name $connection = mysql_connect("localhost", "username", "password"); mysql_select_db("articles", $connection); $aid = mysql_real_esacpe_string($_GET['aid']); $query = "UPDATE articles_description SET visits = visits + 1 WHERE id = $aid"; $result = mysql_query($query) or die(mysql_error()); echo "Record updated successfully"; mysql_close(); Quote Link to comment Share on other sites More sharing options...
teknospr Posted March 7, 2011 Author Share Posted March 7, 2011 Changed it. It does not give me an error, but even though it echoes that it updated the record its not adding the number. Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 7, 2011 Share Posted March 7, 2011 sorry i added a dollor sign. dam you lot so fast so sorry. change the colum to a (int) in the database Quote Link to comment Share on other sites More sharing options...
teknospr Posted March 7, 2011 Author Share Posted March 7, 2011 Sorry about that. Still no error but not adding it. Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 7, 2011 Share Posted March 7, 2011 It not the code no way. is the code includded to the members page where they login? all the big programmers getting up know so us uk wannabe can sleep lol Quote Link to comment Share on other sites More sharing options...
teknospr Posted March 7, 2011 Author Share Posted March 7, 2011 The code is in an article page. Its intended to track the visits to each article. Im looking into the database directly to check for the updated number but its still on 5 (this is testing the code). Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 7, 2011 Share Posted March 7, 2011 what the database look like please. id userid stats date ip Quote Link to comment Share on other sites More sharing options...
teknospr Posted March 7, 2011 Author Share Posted March 7, 2011 Please accept my apologies. I made a mistake. Its working perfectly. Thanks for yout help. Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 7, 2011 Share Posted March 7, 2011 what was it? use the solved button. Quote Link to comment Share on other sites More sharing options...
teknospr Posted March 7, 2011 Author Share Posted March 7, 2011 I wrote aid instead of id. Dumb mistake. Where is the solved button? Quote Link to comment Share on other sites More sharing options...
Psycho Posted March 7, 2011 Share Posted March 7, 2011 use the solved button. The "Solved" button was removed with a recent update to the site. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.