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 : 31907
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
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
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
Newbie Notes #4 - Trapping dumb MySQL query errors
Categories : PHP, Databases, MySQL, Debugging, Beginner Guides
Automatic global variable definer
Categories : PHP, Variables, Beginner Guides
serialize -- Generates a storable representation of a value
Categories : PHP, PHP Functions, 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
Newbie Notes #3 - What went wrong? A useful little debugging aid
Categories : PHP, Beginner Guides, Debugging
Pageinfo: Array containing page URI, page query string (parameters), request method (GET or POST) and the complete URI
Categories : Variables, PHP Options and Info, Arrays, URLs, PHP
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
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
Sending email with random details
Categories : PHP, Email, Debugging
A Custom Error Handling And Debugging Class
Categories : PHP, PHP Classes, Debugging, Errors and Logging
 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";
   }
}
# -------------------------------------- #