|
|
|
One of the major problems faced with dealing with forms, forms submitted, variables used in the form and to find out what exactly should the processing script expect in terms of variable names and variable values is to be able to process each variable which is passed through to the script.
The forms can be submitted using either the POST or GET methods. The function given below gets ALL (and we actually mean ALL!) variables passed through to the processing script, displays them in a table format - 2 columns for variable name and variable value.
This helps in making sure that proper / correct variables are used and processed. This is an excellent tool in debugging your forms.
| function display_post_get() {
if ($_POST) {
echo "Displaying POST Variables: <br> \n";
echo "<table border=1> \n";
echo " <tr> \n";
echo " <td><b>result_name </b></td> \n ";
echo " <td><b>result_val </b></td> \n ";
echo " </tr> \n";
while (list($result_nme, $result_val) = each($_POST)) {
echo " <tr> \n";
echo " <td> $result_nme </td> \n";
echo " <td> $result_val </td> \n";
echo " </tr> \n";
}
echo "</table> \n";
}
if ($_GET) {
echo "Displaying GET Variables: <br> \n";
echo "<table border=1> \n";
echo " <tr> \n";
echo " <td><b>result_name </b></td> \n ";
echo " <td><b>result_val </b></td> \n ";
echo " </tr> \n";
while (list($result_nme, $result_val) = each($_GET)) {
echo " <tr> \n";
echo " <td> $result_nme </td> \n";
echo " <td> $result_val </td> \n";
echo " </tr> \n";
}
echo "</table> \n";
}
}
// End of display_post_get | |
|
|
| Script to check values being submitted by POST or GET method from a form. This script may help diagnose what variables are being supplied by a browser to other php scripts. Categories : HTML, Variables, Debugging, PHP, HTTP | | | The class to check load time of your script
VERY usefull for relatively slow applications, but not only.. Categories : PHP, PHP Classes, Debugging | | | clearing variables in php3 Categories : Variables, Arrays, PHP | | | Check parameters validity. Paranoia was designed to check the validity of the parameters that a php page will receive after a form submission. It can be used to check the variables sent by POST or GET Categories : Algorithms, HTML and PHP, PHP, Variables | | | PhpView 0.1 - simple php viewer, using temporary files and frames.
Categories : PHP, PHP Options and Info, Debugging, HTML and PHP | | | Different Call User Functions Categories : PHP, Functions, Beginner Guides | | | A simple function to prevent undefined $_POST/$_GET/$_SESSION variable errors Categories : PHP, Variables, Errors and Logging | | | Dump the contents of a PHP variable in html format with a recursive list of subfolders and files from a given root directory.
Categories : PHP, Directories, Variables, Arrays | | | This functions compares the current PHP version with a
desired version. Because of the 3 tiered version system, a
direct compare of a string to phpversion() will not be
accurate. Categories : PHP Configuration, PHP, Variables | | | normalize fields and strings used in where (command's Sql) Categories : PHP, Databases, Oracle, Functions | | | How to control the number of decimal places when outputting numbers. Categories : PHP, Strings, Variables | | | Functions to read a template file and fill in PHP variables. It will also fill in array variables, displaying parts of the template multiple times.
Categories : PHP, Variables, Filesystem | | | Function to check connection to MySQL and redirect to an error page if an error occurs Categories : MySQL, PHP, Debugging, Databases | | | Newbie Notes #5 - To double quote, or single quote, that is the question Categories : PHP, Beginner Guides, Variables | | | A quick way set data from a form to a function or other places where you can lose scope. Categories : PHP, HTML and PHP, Variables | |
| | | | sean meese wrote : 1100
That`s a very nice way to display arrays :)
A much smaller solution that I use:
echo "<pre>",print_r($_POST),"</pre>";
echo "<pre>",print_r($_GET),"</pre>";
This also works for ANY type of array:
echo "<pre>",print_r($_SESSION),"</pre>";
echo "<pre>",print_r($_COOKIE),"</pre>";
echo "<pre>",print_r($users),"</pre>";
etc.
It`s not nearly as pretty as the solution posted above, but it works well enough.
| | | | Amado Ohland wrote : 1329
Great code, easy to understand and re-tool for my purposes. I tried it and it worked, simple as that. Well documented. Thanks.
| | | | Moe Coder wrote :1359
first, "to each their own..."
second, here`s mine:
# ---- DEBUGGER TOOL: DUMP INCOMING ---- #
function dumpIncoming() {
foreach ($_GET as $var => $value) {
print "G: $var = $value<br>\n";
}
foreach ($_POST as $var => $value) {
print "P: $var = $value<br>\n";
}
foreach ($_SESSION as $var => $value) {
print "S: $var = $value<br>\n";
}
foreach ($_COOKIE as $var => $value) {
print "C: $var = $value<br>\n";
}
}
# -------------------------------------- #
| |
|
|
|