Welcome
Welcome to dinksoftware

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today!

The importance of error reporting in PHP

Cover's web development including HTML, CSS, PHP, MYSQL and Javascript amongst others...

The importance of error reporting in PHP

Postby Dink » Tue Nov 30, 2010 4:47 pm

Code: Select all
error_reporting(E_ALL);
ini_set('display_errors',1);

will display all PHP errors (which are often hidden/not displayed depending on the PHP settings used) when running a script.

I just used it to find a (stupid) problem I was having. I couldn't for the life of me work out why form contents were not being recovered with $_POST, when in fact as I discovered in the end, they actually were and it was a stupid mistake after that causing the unexpected outcome (the variables holding the $_POST data being empty).

The mistake was
Code: Select all
$var = strip_tags($_POST["var"]);
$var= mysql_real_escape_string($var);
which is fine if you are connected to a MySQL database, althoguh in this instance I wasn't and with only fatal errors messages on by default, it didn't show/state this until I put on the additional error reporting at the start of the post.

:ugeek:
User avatar
Dink
 
Posts: 531
Joined: Sat Jul 11, 2009 9:59 am
Location: Australia

 

Re: The importance of error reporting in PHP

Postby Dink » Tue Dec 21, 2010 9:52 pm

Grr, having problems currents with dynamic fields/arrays and posting them... What I was going to say though was, don't about
Code: Select all
print_r($arrayName);
which will (in most cases) print the contents of an array so you cna see what is/each index of it holds.
User avatar
Dink
 
Posts: 531
Joined: Sat Jul 11, 2009 9:59 am
Location: Australia


Return to Web programming

Who is online

Users browsing this forum: No registered users and 0 guests

cron
suspicion-preferred