error reporting

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

error reporting

Post by mohson »

Ive tried using error reporting but I still get teh age old problem of a blank white screen when I have errors in my code.

Ive been to php.net and this is what they say:

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)


so I put this code in my file like so:

Code: Select all

<?php

error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

// config-------------------------------------
$host = "*"; //your database host
$user = "*"; // your database user name
$pass = "*"; // your database password
$db = "contact_management_system"; // your database name

$filename = "people.html"; // name of this file
$option = array (5, 10, 20, 50, 100, 200);
$default = 100; // default number of records per page
$action = $_SERVER['PHP_SELF']; // if this doesn't work, enter the filename


// database query. Enter your query here

 $query = 	"SELECT 
		o.org_id,o.web_url,
		p.person_id,p.org_id,p.salutation,p.firstname,p.surname,
		p.organisation,p.role,p.address1,p.address2,p.city,
		p.postcode,p.telephone,p.mobile,p.fax,p.dateoflastcontact,
		p.datecontactagain,p.notes,p.email, 

		DATE_FORMAT(dateoflastcontact, '%M/%Y') 
		AS dateoflastcontact, DATE_FORMAT(datecontactagain, '%M/%Y') 
		AS datecontactagain 

		FROM people p LEFT JOIN organisations o
     		ON o.org_id = p.org_id		
		ORDER BY firstname";



// end config---------------------------------
?>
but nothing happens - and when i purposefully add as extra < to the last ? to make it <?> to get an error nothing is reported.

Two questions how good is this error reporting anyway, does it tell you which line of code is dodgy

and secondly why are my erros not being reported.?
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

config file

Post by mohson »

Ive just used

<?php error_reporting(); ?>

and the config file says that error_reporting is switched off

Obvious but this has to be the problem hasnt it?????????
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Stick that at the top of everything. No matter what is in php.ini this way produce errors for you :wink:

Code: Select all

error_reporting(E_ALL);
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

what exactly does this error reporting show ??? Ive even tried what you suggested and to test it out I put an extra <?> instead of ?> at the end and theres NO error reporting is it just me or does does this error reporting not show errors such as this????????
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Not entirely sure - but don't you need to enable error_reporting from php.ini - not just the error level to report, but the METHOD, i.e. logged, displayed, etc.

If error displaying is off - wouldn't a blank page be pretty normal?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

Long Answer :
http://us2.php.net/error_reporting

Short Answer : no, it doesn't matter if display is turned off.
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

thats what I thought but then I was told that if you used

Code: Select all

error_reporting(E_ALL);
that it wouldnt matter if error reporting was switched off
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

ok can you please tell me what would happen if you put <?> instead of ?> at the end of your code what kind of error message would you get because I only get a blank screen
Ive been working without error reporting for a whole year and its just too difficult
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

just put error_reporting(E_ALL); in your code somewhere...

example

Code: Select all

error_reporting(E_ALL);
echo 'blah blah no errors';
echo 'this should give me an error' or something; haha
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

This is what I am trying to explain I have put all the suggested error reporting code in my code but when there is an error I onlt get a blank screen
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post by infolock »

show me an example of code you are trying to use that should give you an error then please
mohson
Forum Contributor
Posts: 372
Joined: Thu Dec 02, 2004 6:58 am
Location: London

Post by mohson »

ok this code works fine but then when I add an extra < to the ?> it should report an error so ?> beocme <?>

ok heres the code:

Code: Select all

<p>

<strong><font size="4">Personal Details</font></strong><br>

 <br>
<p><font><strong>Select a record for editing by clicking on its ID.</strong></font>
<br><a href="queries.html"> Quick Search: Find a Contact</a><br>
<hr>

 


<?php


//error reporting
php error_reporting(E_ALL);

// config-------------------------------------
$host = "*"; //your database host
$user = "*"; // your database user name
$pass = "*"; // your database password
$db = "contact_management_system"; // your database name

$filename = "people.html"; // name of this file
$option = array (5, 10, 20, 50, 100, 200);
$default = 100; // default number of records per page
$action = $_SERVER['PHP_SELF']; // if this doesn't work, enter the filename


// database query. Enter your query here

 $query = 	"SELECT 
		o.org_id,o.web_url,
		p.person_id,p.org_id,p.salutation,p.firstname,p.surname,
		p.organisation,p.role,p.address1,p.address2,p.city,
		p.postcode,p.telephone,p.mobile,p.fax,p.dateoflastcontact,
		p.datecontactagain,p.notes,p.email, 

		DATE_FORMAT(dateoflastcontact, '%M/%Y') 
		AS dateoflastcontact, DATE_FORMAT(datecontactagain, '%M/%Y') 
		AS datecontactagain 

		FROM people p LEFT JOIN organisations o
     		ON o.org_id = p.org_id		
		ORDER BY firstname";



// end config---------------------------------

	
$opt_cnt = count ($option);

$go = $_GET['go'];
// paranoid
if ($go == "") {
$go = $default;
}
elseif (!in_array ($go, $option)) {
$go = $default;
}
elseif (!is_numeric ($go)) {
$go = $default;
}
$nol = $go;
$limit = "0, $nol";
$count = 1; 

echo "<form name=\"form1\" id=\"form1\" method=\"get\" action=\"$action\">\r\n";
echo "<select name=\"go\" id=\"go\">\r\n";

for ($i = 0; $i <= $opt_cnt; $i ++) {
if ($option[$i] == $go) {
echo "<option value=\"".$option[$i]."\" selected=\"selected\">".$option[$i]."</option>\r\n";
} else {
echo "<option value=\"".$option[$i]."\">".$option[$i]."</option>\r\n";
}
}

echo "</select>\r\n";
echo "<input type=\"submit\" name=\"Submit\" id=\"Submit\" value=\"Go\" />\r\n";
echo "</form>\r\n";

$connection = mysql_connect ($host, $user, $pass) or die ("Unable to connect");
mysql_select_db ($db) or die ("Unable to select database $db");



// control query------------------------------
/* this query checks how many records you have in your table.
I created this query so we could be able to check if user is
trying to append number larger than the number of records
to the query string.*/
$off_sql = mysql_query ("$query") or die ("Error in query: $off_sql".mysql_error());
$off_pag = ceil (mysql_num_rows($off_sql) / $nol);
//-------------------------------------------- 


$off = $_GET['offset'];
//paranoid
if (get_magic_quotes_gpc() == 0) {
$off = addslashes ($off);
}
if (!is_numeric ($off)) {
$off = 1;
}
// this checks if user is trying to put something stupid in query string
if ($off > $off_pag) {
$off = 1;
}

if ($off == "1") {
$limit = "0, $nol";
}
elseif ($off <> "") {
for ($i = 0; $i <= ($off - 1) * $nol; $i ++) {
$limit = "$i, $nol";
$count = $i + 1;
}
} 




// Query to extract records from database.
$sql = mysql_query ("$query LIMIT $limit") or die ("Error in query: $sql".mysql_error()); 



// Define your colors for the alternating rows

$color1 = "#ADD8E6";$color2 = "#E0FFFF";
$color = $color2;echo 

"<table width=\"50%\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\">

    <tr>
		<td><b><small>RecNo</small></b></td>
		<td><b><small>PID</small></b></td>
		<td><b><small>OID</small></b></td>
		<td><b><small>Title</small></b></td>
		<td><b><small>First Name</small></b></td>
		<td><b><small>Surname</small></b></td>
		<td><b><small>Organisation</small></b></td>
		<td><b><center><small>Role</small></center></b></td>
		<td><b><small>Address(1)</small></b></td>
		<td><b><small>Address(2)</small></b></td>
		<td><b><small>City</small></b></td>
		<td><b><small>Post Code</small></b></td>
		<td><b><small>Telephone</small></b></td>
		<td><b><small>Mobile</small></b></td>
		<td><b><small>Fax</small></b></td>
		<td><b><small>Last Contact</small></b></td>
		<td><b><small>Contact Again</small></b></td>
		<td><b><small>Notes</small></b></td>";




while ($row = mysql_fetch_object($sql)) 






{($color==$color2)? $color = $color1 : $color = $color2;


echo "<tr bgcolor=\"$color\"><td>".$count . '</td><td> ' . $row->person_id .'</td><td>'.        
	
	$row->org_id.'</td><td>'. 
	$row->salutation .'</td><td>'.         
	
	'<a href=mailto:'.$row->email.'>'.$row->firstname .'</a></td><td>'.
	'<a href=mailto:'.$row->email.'>'.$row->surname .'</a></td><td>'.       
	
	'<a href=http://'.$row->web_url.'>'.$row->organisation . '</a></td><td>'.

	
	$row->role.'</td><td>'.       
 	$row->address1 .'</td><td>'.        
	$row->address2 .'</td><td>'.       
 	$row->city .'</td><td>'.       
 	$row->postcode .'</td><td>'.        
	$row->telephone .'</td><td>'.        
	$row->mobile .'</td><td>'.        
	$row->fax .'</td><td>'.        
	$row->dateoflastcontact.'</td><td>'.        
	$row->datecontactagain.'</td><td>'.
	$row->notes.'</td><td>';

$count += 1;
}

echo "</table>"; 

echo "<br /><br />\r\n";
if ($off <> 1) {
$prev = $off - 1;
echo "[ < <a href=\"$filename?offset=$prev&go=$go\">prev</a> ] \r\n";
}
for ($i = 1; $i <= $off_pag; $i ++) {
if ($i == $off) {
echo "[<b> $i </b>] \r\n";
} else {
echo "[ <a href=\"$filename?offset=$i&go=$go\">$i</a> ] \r\n";
}
}
if ($off < $off_pag) {
$next = $off + 1;
echo "[ <a href=\"$filename?offset=$next&go=$go\">next</a> > ] \r\n";
}

echo "<br /><br />\r\n";
echo "Page $off of $off_pag<br />\r\n";




<?>
this shouldnt work because of the <?> at the end

but theres no error reporting the screen just goes blank???
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  1. is display_errors on?
  2. line 17 of your recent code post has "php error_reporting..." that should produce an error before the error reporting line is fully parsed.
  3. If you have access to the php.ini change the settings there, if not and your server supports .htaccess, you can use that to make the settings happen before your script is even loaded into memory.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

As feyd mentioned... what is this?

Code: Select all

//error reporting
php error_reporting(E_ALL);
Please change to

Code: Select all

//error reporting
error_reporting(E_ALL);
Post Reply