Jacob Windsor
Jacob Windsor

Reputation: 6980

Apache error log shows PHP errors but no errors outputted by PHP

I have just had a look at the apache error log and the file is huge! There have been no errors on the site itself and none are outputted by PHP but in the error log there are many undefined variables etc.

Here's a couple of examples:

[Fri May 31 14:04:15 2013] [error] [client 127.0.0.1] PHP Notice:  Undefined variable: ID in C:\\wamp\\www\\artist_profile.php on line 189, referer: http://localhost/Discover

[Fri May 31 14:04:15 2013] [error] [client 127.0.0.1] PHP Stack trace:, referer: http://localhost/Discover

[Fri May 31 14:04:15 2013] [error] [client 127.0.0.1] PHP   1. {main}() C:\\wamp\\www\\artist_profile.php:0, referer: http://localhost/Discover

I have no idea why this is happening and obviously need to sort it before the site goes live.

I can't really give any more information on this because I am clueless. I have playing around with include and include_once, swapping them around but this had no effect. My only other thought is that the site use a history API script to fetch pages through ajax without a full refresh. Maybe because only part of the new page is loaded in errors are being logged. But I don't see why they would be logged in apache and not outputted into the browser.

Edit

The variable $ID that the notice is identifying is gotten from a mysql query and identified as such;

$ID = $row['ID'];//never echo this

Line 189 is just $ID inside another query. I can echo out $ID anywhere on the page and no error will be displayed. By the way the comment is there to remind anyone not to echo it out for security reasons.

Edit Where $ID is set.

<?php require("includes/database.php"); 
       $url = $_SERVER["REQUEST_URI"]; //get url for db
       $url = substr($url, 1);
       $result = mysql_query ("SELECT * ,
                              (SELECT COUNT(*) FROM artist_follows WHERE follows_ID = A.ID) AS followers,
                              (SELECT COUNT(*) FROM artist_follows WHERE ID = A.ID) AS following,
                              (SELECT COUNT(*) FROM tracks WHERE ID = A.ID) AS tracks
                              FROM artists A WHERE url = '$url' LIMIT 1");
       $count = mysql_num_rows($result);
       if ($count === 0){
       //redirect to 404
       header ("location:404");
       }
       while($row = mysql_fetch_array($result)){
          $ID = $row['ID'];//never echo this           
      }

Line 189:

WHERE E.ID = '$ID'
GROUP BY E.E_ID
ORDER BY E.timestamp DESC LIMIT 20"

Upvotes: 0

Views: 2078

Answers (2)

MaxiNet
MaxiNet

Reputation: 1028

Try adding this at the beginning of your file:

error_reporting(E_ALL);
ini_set("display_errors", 1);

Upvotes: 1

Fabio
Fabio

Reputation: 23480

This is because they are just notices. Those are probably disabled in your php.ini. You can either activate by editing it or simply add in your script

error_reporting(E_ALL);
ini_set("display_errors", 1);

You might want to have a look at documentation

Upvotes: 1

Related Questions