Jump to content

[SOLVED] Simple, Simple php stats script not working


patheticsam

Recommended Posts

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!

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

Archived

This topic is now archived and is closed to further replies.

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