0

I'm troubleshooting a problem on my site and I have narrowed it down to the php being run twice. I assume this means the page is loaded twice but the catch is that the code is only echoed or printed once. I figured this out using ChromePHP to log some text. That text prints in the console twice every now and again.

The main issue is that I'm making a mysql query and setting a variable. In an example. It prints the ID number it gets as 2, but then the code randomly loads again and that variable is now set to something else... lets say 15 or whatever. But visually the echoed variable is still 2.

include 'php/classes/ChromePhp.php';
$link = mysqli_connect($host, $dbuser, $dbpass, $dbname );

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

if ($result = mysqli_query($link,'SELECT questionID FROM questions order by rand() limit 1')) {
    $row = mysqli_fetch_array($result);
    printf("Question ", $row['questionID']);
    mysqli_free_result($result);
    ChromePhp::log('QUESTIONID '.$row['questionID']);
}       
if($link) 
    mysqli_close($link);
?>

I've looked around and people say it could be the favicon being loaded separately or the .htaccess redirect which I use. I took the .htaccess off and I still have this issue.

Any pointers to a direction would be nice.

Thanks

6
  • ...and if you remove the echo statement on your penultimate line do neither 2 nor 15 get printed?
    – ChrisW
    Nov 1, 2012 at 17:23
  • For your own safety and welfare you should really not be using the deprecated and dangerous mysql_query interface. PDO or mysqli are considerably easier to use properly.
    – tadman
    Nov 1, 2012 at 17:24
  • Does your page display additional HTML besides H1 tag you posted in your code?
    – Salman A
    Nov 1, 2012 at 17:32
  • I updated this page to use mysqli and I still get the same issue. I used to have more HTML but I have reduced the code to this so I can find the issue. What you see is what you get. Nov 1, 2012 at 17:45
  • there. Its as stripped down as I can get it. I've been programming this site for months now and this is the first time I've seen this. Nov 1, 2012 at 17:50

1 Answer 1

0

I discovered it was a Google Chrome Extension: FirePHP that was causing the reload of code. Once I deleted the extension everything started working again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.