patheticsam Posted June 3, 2009 Share Posted June 3, 2009 Hi! I did a really, really..REALLY simple php statistic script but I just don't understand why it's not working..it's just so simple that i just can't figure out why it's not working...If anyone could help me out it would be realle appreciated... Here's the code : <?php $con = mysql_connect("localhost","user","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $sql = "SELECT `id`, `section`, `visit` FROM stats WHERE id = '1'"; $req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error()); while($data = mysql_fetch_assoc($req)) { $stats = "$data[visit]+1"; } mysql_query(" UPDATE stats SET `visit` = '$stats' WHERE id = '1'") or die(mysql_error()); ?> (I also triedc with $stats = "$data[visit]++"; ...still not working...) Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/160848-solved-simple-simple-php-stats-script-not-working/ Share on other sites More sharing options...
Alex Posted June 3, 2009 Share Posted June 3, 2009 $stats = ++$data['visit']; You could use the ++ before or after the variable. It's suggested you use it before because it won't alter the value of $data['visit'], but unless you're using that again and want the original value it doesn't matter. Quote Link to comment https://forums.phpfreaks.com/topic/160848-solved-simple-simple-php-stats-script-not-working/#findComment-848892 Share on other sites More sharing options...
patheticsam Posted June 3, 2009 Author Share Posted June 3, 2009 still not working.... Quote Link to comment https://forums.phpfreaks.com/topic/160848-solved-simple-simple-php-stats-script-not-working/#findComment-848895 Share on other sites More sharing options...
Alex Posted June 3, 2009 Share Posted June 3, 2009 Also a problem with your second query.. mysql_query(' UPDATE stats SET `visit`="' . $stats . '" WHERE id = "1"') or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/160848-solved-simple-simple-php-stats-script-not-working/#findComment-848897 Share on other sites More sharing options...
patheticsam Posted June 3, 2009 Author Share Posted June 3, 2009 Working! Thanx Quote Link to comment https://forums.phpfreaks.com/topic/160848-solved-simple-simple-php-stats-script-not-working/#findComment-848898 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.