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!

Link to comment
Share on other sites

$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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