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(); ?> Link to comment https://forums.phpfreaks.com/topic/229823-adding-a-number-every-visit/ 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. Link to comment https://forums.phpfreaks.com/topic/229823-adding-a-number-every-visit/#findComment-1183790 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(); Link to comment https://forums.phpfreaks.com/topic/229823-adding-a-number-every-visit/#findComment-1183794 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. Link to comment https://forums.phpfreaks.com/topic/229823-adding-a-number-every-visit/#findComment-1183796 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 Link to comment https://forums.phpfreaks.com/topic/229823-adding-a-number-every-visit/#findComment-1183797 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. Link to comment https://forums.phpfreaks.com/topic/229823-adding-a-number-every-visit/#findComment-1183800 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 Link to comment https://forums.phpfreaks.com/topic/229823-adding-a-number-every-visit/#findComment-1183802 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). Link to comment https://forums.phpfreaks.com/topic/229823-adding-a-number-every-visit/#findComment-1183806 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 Link to comment https://forums.phpfreaks.com/topic/229823-adding-a-number-every-visit/#findComment-1183809 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. Link to comment https://forums.phpfreaks.com/topic/229823-adding-a-number-every-visit/#findComment-1183812 Share on other sites More sharing options...
redarrow Posted March 7, 2011 Share Posted March 7, 2011 what was it? use the solved button. Link to comment https://forums.phpfreaks.com/topic/229823-adding-a-number-every-visit/#findComment-1183814 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? Link to comment https://forums.phpfreaks.com/topic/229823-adding-a-number-every-visit/#findComment-1183829 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. Link to comment https://forums.phpfreaks.com/topic/229823-adding-a-number-every-visit/#findComment-1183860 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.