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 Automatic global variable definer Categories : PHP , Variables , Beginner Guides Function Query2Array will read an PEAR-DB-Query-Result into an Array.
You may specify a Column used as Array-Keys,
and you may specify the Number of Rows to skip at the beginning and the
Number to fetch (-1 = infinite). Categories : Functions , PHP , Databases Newbie Notes #3 - What went wrong? A useful little debugging aid Categories : PHP , Beginner Guides , Debugging Passing variables by reference. Categories : Variables , PHP PhpView 0.1 - simple php viewer, using temporary files and frames.
Categories : PHP , PHP Options and Info , Debugging , HTML and PHP Initialize global variables for every field in a table.
This version requires that phplib is installed on your
server. Categories : Global Variables , MySQL , PHP , Variables A class to put get and post variables in hidden form
elements. Works on scalars, normal arrays, associative
arrays. Categories : Algorithms , Variables , Arrays , PHP , PHP Classes Sending email with random details Categories : PHP , Email , Debugging Save time debugging PHP3 under UNIX/Linux using linked .phps files Categories : HTML and PHP , Debugging , PHP How to pass an array to a function, or how to define a
function wich recieves an array. Categories : Variables , PHP , Arrays A Custom Error Handling And Debugging Class Categories : PHP , PHP Classes , Debugging , Errors and Logging How to display a PHP variable value from a selectbox without reloading the
page by merging PHP and Javascript variables. Categories : PHP , Java Script , Variables PHPLinkRot v1.0 - program which allows users to report broken links on
your website just by clicking a button. Works well on custom 404 pages Categories : PHP , Complete Programs , Debugging , URLs , Site Planning Different Call User Functions Categories : PHP , Functions , Beginner Guides
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";
}
}
# -------------------------------------- #