help needed: script execution timeout for no reason (mysql query) 
Author Message
 help needed: script execution timeout for no reason (mysql query)

Could someone please help me on the following.

I have a php stats page which i have created myself, and this links to
a mysql database. the script stops the first time its run (on the
$qstr="SELECT userid FROM hfstats where userid={$temp}"; line) but the
second time you run the query (once the cookie is there) it runs
perfect. the problem is i cant have this because the use cannot visit
the page the first time if i want to record the stats.

following is a dump of the database structure and the PHP code.

thanks in advance for any help, if you could help could you please

thanks again.

CREATE TABLE hfstats (
  hitid int(11) NOT NULL auto_increment,
  logtime timestamp(14) NOT NULL,
  sourcepage varchar(255) default NULL,
  userid int(11) NOT NULL default '0',
  referer varchar(255) default NULL,
  remoteip varchar(15) default NULL,
  req_uri varchar(255) default NULL,
  x_fowarded varchar(255) default NULL,
  remotehost varchar(255) default NULL,
  browser text,
  PRIMARY KEY  (hitid)
) TYPE=MyISAM;

<?php

include("dbcon.php");

if(!$_COOKIE['hfUserID']){
        $foundmatch=TRUE;
        do {
                setcookie("hfUserID", $temp=mt_rand(), time()+43200);

                $qstr="SELECT userid FROM hfstats where userid={$temp}";

                $result = mysql_query($qstr) or die("Invalid query:"
.mysql_error());

                if(!mysql_num_rows($result) > 0){
                        $foundmatch=FALSE;
                }
        } while($foundmatch = TRUE);
        //$qstr="INSERT INTO hfstats VALUES()";

Quote:
}else{

        $temp = $_COOKIE['hfUserID'];
Quote:
}

echo "<html><body><p>Welcome</p>";

$qstr="INSERT INTO hfstats VALUES(NULL,NULL,'" . getenv("PATH_INFO") .
"','{$temp}','{$_SERVER['HTTP_REFERER']}','" . getenv("REMOTE_ADDR") .
"','{$_SERVER['REQUEST_URI']}','{$_SERVER['HTTP_X_FORWARDED_FOR']}','"
. getenv("REMOTE_HOST") . "','" . getenv("HTTP_USER_AGENT") . "')";
$result = mysql_query($qstr) or die("Query error, contact the
webmaster");

?>



Sun, 26 Jun 2005 06:11:29 GMT  
 help needed: script execution timeout for no reason (mysql query)
Quote:

> Could someone please help me on the following.

> I have a php stats page which i have created myself, and this links to
> a mysql database. the script stops the first time its run (on the
> $qstr="SELECT userid FROM hfstats where userid={$temp}"; line) but the
> second time you run the query (once the cookie is there) it runs
> perfect. the problem is i cant have this because the use cannot visit
> the page the first time if i want to record the stats.

> following is a dump of the database structure and the PHP code.

> thanks in advance for any help, if you could help could you please

> thanks again.

> CREATE TABLE hfstats (
>   hitid int(11) NOT NULL auto_increment,
>   logtime timestamp(14) NOT NULL,
>   sourcepage varchar(255) default NULL,
>   userid int(11) NOT NULL default '0',
>   referer varchar(255) default NULL,
>   remoteip varchar(15) default NULL,
>   req_uri varchar(255) default NULL,
>   x_fowarded varchar(255) default NULL,
>   remotehost varchar(255) default NULL,
>   browser text,
>   PRIMARY KEY  (hitid)
> ) TYPE=MyISAM;

> <?php

> include("dbcon.php");

> if(!$_COOKIE['hfUserID']){
>    $foundmatch=TRUE;
>    do {
>            setcookie("hfUserID", $temp=mt_rand(), time()+43200);

>            $qstr="SELECT userid FROM hfstats where userid={$temp}";

>            $result = mysql_query($qstr) or die("Invalid query:"
> .mysql_error());

>            if(!mysql_num_rows($result) > 0){
>                    $foundmatch=FALSE;
>            }
>    } while($foundmatch = TRUE);

                ^^^^^^^^^^^^^^^^^^

        That will result in a never ending loop.  You use == to compare values
in php, = assigns the value, which is always true unless you assing
false or 0.  Change that to while ($foundmatch==true); and it should be
fine.

- Show quoted text -

Quote:
>    //$qstr="INSERT INTO hfstats VALUES()";
> }else{
>    $temp = $_COOKIE['hfUserID'];
> }
> echo "<html><body><p>Welcome</p>";

> $qstr="INSERT INTO hfstats VALUES(NULL,NULL,'" . getenv("PATH_INFO") .
> "','{$temp}','{$_SERVER['HTTP_REFERER']}','" . getenv("REMOTE_ADDR") .
> "','{$_SERVER['REQUEST_URI']}','{$_SERVER['HTTP_X_FORWARDED_FOR']}','"
> . getenv("REMOTE_HOST") . "','" . getenv("HTTP_USER_AGENT") . "')";
> $result = mysql_query($qstr) or die("Query error, contact the
> webmaster");

> ?>



Sun, 26 Jun 2005 05:35:01 GMT  
 help needed: script execution timeout for no reason (mysql query)

Quote:

>> } while($foundmatch = TRUE);
> ^^^^^^^^^^^^^^^^^^

> That will result in a never ending loop.  You use == to compare values
> in php, = assigns the value, which is always true unless you assing
> false or 0.  Change that to while ($foundmatch==true); and it should be
> fine.

One interesting trick to help yourself catch this type of error is to get
into the habit of reversing the arguments for the ==, like this:

while( true == $foundmatch)

This helps because:
while( true = $foundmatch )

will fail at compile-time, where as ($foundmatch = true) is a
syntactically-valid statement and will compile fine but contains a logic
error.

--
----- stephan beal
Registered Linux User #71917 http://counter.li.org
I speak for myself, not my employer. Contents may
be hot. Slippery when wet. Reading disclaimers makes
you go blind. Writing them is worse. You have been Warned.



Sun, 26 Jun 2005 18:08:15 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. MySQL query in PHP: Not query zero amounts also removes null amounts from query

2. MySql query...Please help

3. help with mysql query

4. CMUCL and Motif: need some help about Timeouts

5. Help! need to time function execution in milleseconds

6. execution error help needed

7. SQL query timeout

8. Newbie needs help setting up user MySQL thru PHP

9. Help needed - mySQL connection problem

10. HELP WITH MYSQL AND PHP NEEDED!!!

11. Novice needs help with SQL (Max,Min, etc) queries on RealDBs

12. problem with threading mysql queries in ruby

 

 
Powered by phpBB® Forum Software