WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search


Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder



Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Display variables when a form is submitted using POST/GET
Categories : PHP, Functions, Variables, Debugging Click here to Update Your Picture
Narendra Jain
Date : May 03rd 2004
Grade : 4 of 5 (graded 3 times)
Viewed : 32340
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Narendra Jain
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

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
Automatic global variable definer
Categories : PHP, Variables, Beginner Guides
How to implement a session tracking system.
Categories : PHP, Sessions, Variables
Newbie Notes #3 - What went wrong? A useful little debugging aid
Categories : PHP, Beginner Guides, Debugging
clearing variables in php3
Categories : Variables, Arrays, PHP
Memory Growth, Memory Leaks, Garbage Collection.
Categories : Debugging, PHP
An email validation script that actually checks against the recipient's mail server.
Categories : Email, Complete Programs, PHP, Network, Debugging
Custom error messages.
Categories : PHP, Debugging
PhpView 0.1 - simple php viewer, using temporary files and frames.
Categories : PHP, PHP Options and Info, Debugging, HTML and PHP
Sending email with random details
Categories : PHP, Email, Debugging
A Custom Error Handling And Debugging Class
Categories : PHP, PHP Classes, Debugging, Errors and Logging
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
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
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 "&lt;pre&gt;",print_r($_POST),"&lt;/pre&gt;";
echo "&lt;pre&gt;",print_r($_GET),"&lt;/pre&gt;";

This also works for ANY type of array:

echo "&lt;pre&gt;",print_r($_SESSION),"&lt;/pre&gt;";
echo "&lt;pre&gt;",print_r($_COOKIE),"&lt;/pre&gt;";
echo "&lt;pre&gt;",print_r($users),"&lt;/pre&gt;";

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 =&gt; $value) {
      print "G: $var = $value&lt;br&gt;\n";
   }
   foreach ($_POST as $var =&gt; $value) {
      print "P: $var = $value&lt;br&gt;\n";
   }
   foreach ($_SESSION as $var =&gt; $value) {
      print "S: $var = $value&lt;br&gt;\n";
   }
   foreach ($_COOKIE as $var =&gt; $value) {
      print "C: $var = $value&lt;br&gt;\n";
   }
}
# -------------------------------------- #