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 : 31572
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
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
Example of function to send out email if error occurs
Categories : PHP, Email, Debugging, Errors and Logging
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
PhpView 0.1 - simple php viewer, using temporary files and frames.
Categories : PHP, PHP Options and Info, Debugging, HTML and PHP
PHP Dump in html format the contents of one array variable with a recursive list of the nested array variables inside.
Categories : PHP, Arrays, Variables
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
getting the name of the current script and query string
Categories : PHP, Global Variables, Variables, URLs
Passing variables by reference.
Categories : Variables, PHP
[PHP5] PHP Debugger and Helper
Categories : PHP, PHP Classes, Errors and Logging, Debugging, XML
Newbie Notes #5 - To double quote, or single quote, that is the question
Categories : PHP, Beginner Guides, Variables
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
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
normalize fields and strings used in where (command's Sql)
Categories : PHP, Databases, Oracle, Functions
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
 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";
   }
}
# -------------------------------------- #