[PHP] counter freezes whole site!

2003-02-05 Thread Pag

	Hi, I am having a serious problem on my site. It was working fine until a 
day ago, when it simply freezes. After i made a few checks i realized it 
loops on this code. I tried everything but i cant understand why and i am 
going crazy trying to figure it out!
	This code is supposed to write a 24h cookie at first visit, and then 
checks for it at every refresh, if the cookie doesnt exist, it increases a 
counter on the DB. Simple, right? Then why did it stop working out of the 
blue? It loops on the refresh, keeps thinking the cookie is not active, so 
it keeps adding +1 to the counter. What am i doing wrong? How can i fix it?
	oh, this code is right at the top of my main page.
	Thanks!


?
if ($pvisita == '1') {
break;
} else {

include ('databaseinfo.txt');
$ligacao=mysql_connect($h, $u, $p) or die(Erro ao aceder a MySQL);
@mysql_select_db($DBname) or die(Unable to select database  . $DBname);
$resultado = mysql_query (select * from counttable where id='0');

if ($resultado) {
$registo = mysql_fetch_array($resultado);
$id = $registo[ID];
$contador = $registo[contador];
$contador = $contador + 1;
$resultado2 = mysql_query (update counttable set contador='$contador' 
where id='0');
setcookie(pvisita, 1, time() + 86400);
header(Location: $PHP_SELF);

}else{
print (não há registos);
break;
}

}
?



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] counter freezes whole site!

2003-02-05 Thread John W. Holmes
   This code is supposed to write a 24h cookie at first visit, and
then
 checks for it at every refresh, if the cookie doesnt exist, it
increases a
 counter on the DB. Simple, right? Then why did it stop working out of
the
 blue? It loops on the refresh, keeps thinking the cookie is not
active, so
 it keeps adding +1 to the counter. What am i doing wrong? How can i
fix
 it?
 ?
 if ($pvisita == '1') {

Try if($_COOKIE['pvisita'] == 1) instead...

 break;
 } else {
 
 include ('databaseinfo.txt');
 $ligacao=mysql_connect($h, $u, $p) or die(Erro ao aceder a MySQL);
 @mysql_select_db($DBname) or die(Unable to select database  .
$DBname);
 $resultado = mysql_query (select * from counttable where id='0');
 
 if ($resultado) {
 $registo = mysql_fetch_array($resultado);
 $id = $registo[ID];
 $contador = $registo[contador];
 $contador = $contador + 1;
 $resultado2 = mysql_query (update counttable set contador='$contador'
 where id='0');
 setcookie(pvisita, 1, time() + 86400);
 header(Location: $PHP_SELF);
 
 }else{
 print (não há registos);
 break;
 }

Also, for the rest of that, it'd be easier to just issue one query such
as:

Update countable set contador = contador + 1 where id = 0

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php