|
|
|
NewbieNotes is a little series of tips for people who are new to PHP to give them a few handy tips that the more experienced of us use often
You're sure your PHP was right but you're getting the wrong results. What went wrong?
It's usually down to doing something stupid - we've all done it, and continue to do it, no matter how long we've been writing PHP
This handy little three line function helps you work out what went wrong.
| <?php
function pv($v)
{
echo "<pre>\n";
print_r($v);
echo "</pre>\n";
}
?> | |
That amazingly stupid bit of code can be your best friend!
You just submitted a form and nothing happenned - why not? at the top of your code throw in pv($_POST) and you can see what came through - was it what you expected?
You got a row back from a database query but your code don't work. Hit it with a pv($row) - assuming $row is the variable you got back from the database query - does it all look right?
There are loads of uses for pv() - it's your friend when things go wrong. It'll display the entire contents of an array with thousands of elements - if that's what's causing the problem.
|
|
| Newbie Notes #4 - Trapping dumb MySQL query errors Categories : PHP, Databases, MySQL, Debugging, Beginner Guides | | | Cut your MySQL Connections to 1 line of code Categories : PHP, Beginner Guides, Databases, MySQL | | | Basic Authentication with sessions Categories : PHP, Beginner Guides, Authentication, Form Processing, Sessions | | | Introduction to Language Files Categories : PHP, Filesystem, Beginner Guides | | | News management class Categories : PHP, PHP Classes, Beginner Guides | | | A flat file counter Categories : PHP, Cookies, Filesystem, Beginner Guides | | | The class to check load time of your script
VERY usefull for relatively slow applications, but not only.. Categories : PHP, PHP Classes, Debugging | | | PhpView 0.1 - simple php viewer, using temporary files and frames.
Categories : PHP, PHP Options and Info, Debugging, HTML and PHP | | | PHP Email image generator - hide your email from bots - using the GD Library Categories : PHP, Graphics, GD image library, Beginner Guides | | | Different Call User Functions Categories : PHP, Functions, Beginner Guides | | | Creating a Language File Categories : PHP, Beginner Guides, Filesystem | | | a PHP Function to Get only the filename (remove the extension) using regular expressions. Categories : PHP, Regexps, Beginner Guides | | | A beginner's session handling class Categories : PHP, PHP Classes, Sessions, Beginner Guides | | | email new items in db Categories : PHP, Email, Databases, MySQL, Beginner Guides | | | A very simple PHP single password cookie based login without usernames. Categories : PHP, Cookies, Security, Beginner Guides | |
|
|
|