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! 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. 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.... 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()); 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 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
Archived
This topic is now archived and is closed to further replies.