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 : 31985
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 control the number of decimal places when outputting numbers.
Categories : PHP, Strings, Variables
translate.php - Assocciative array example, passing a reference to a function.
Categories : PHP, Arrays, Languages, 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
Visits-tracking
Categories : PHP, Databases, MySQL, Errors and Logging, Functions
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
A database abstraction layer for the PHP Oracle 8 module (available from PHP 3.0.5). It supports persistent connections, fetching rows into arrays, prepare/execute (variable binding) and has a new and improved error interface.
Categories : Databases, Oracle, PHP, Arrays, Variables
serialize -- Generates a storable representation of a value
Categories : PHP, PHP Functions, Variables
Global Dump Highlighted
Categories : PHP, Variables, Global Variables
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
Example of function to send out email if error occurs
Categories : PHP, Email, Debugging, Errors and Logging
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
Inline Scope Control - The inline class provides methods for creating and destroying local variable scopes. Simply put, local scopes are spaces where some or all of the global variables are temporarily hidden.
Categories : PHP, PHP Classes, Variables
getting the name of the current script and query string
Categories : PHP, Global Variables, Variables, URLs
 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";
   }
}
# -------------------------------------- #