'Print out post values

I have a form that has multiple fields, and for testing purposes is there a way I could print out the values entered in all the fields, without having to individually print each value.

php


Solution 1:[1]

For extra credit, I always have:

function pre($data) {
    print '<pre>' . print_r($data, true) . '</pre>';
}

Whenever I need to debug an array - which is very often - I just do pre($arr); to get a nicely formatted dump.

Solution 2:[2]

print_r() / var_dump() are simple and gets the job done.

If you want a styled/dynamic option check out Krumo:

http://krumo.sourceforge.net/

A lot of developers use print_r() and var_dump() ... Krumo is an alternative: it does the same job, but it presents the information beautified using CSS and DHTML.

Solution 3:[3]

I basically use:

echo "<pre>"; print_r($_POST) ;  echo "</pre>";

It prints the post values in a nice formatted way.

Solution 4:[4]

If you pay close attention to the $_POST[] or $_GET[] method, you will realize that both of them are actually arrays.This means that you can play around with them just like you do with any other arrays.

For example, you can print_r($_POST) and you will see everything the way were entered..

Solution 5:[5]

This PHP code doesn't require any knowledge of the fields in the form that submits to it, it just loops through all of the fields, including multiple-choice fields (like checkboxes), and spits out their values.

<?php
// loop through every form field
while( list( $field, $value ) = each( $_POST )) {
   // display values
   if( is_array( $value )) {
      // if checkbox (or other multiple value fields)
      while( list( $arrayField, $arrayValue ) = each( $value ) {
         echo "<p>" . $arrayValue . "</p>\n";
      }
   } else {
      echo "<p>" . $value . "</p>\n";
   }
}
?>

Solution 6:[6]

If you're debugging a lot, I would recommend installing XDebug. It makes var_dump's very pretty and useful (giving you the type and length of the variable aswell).

Solution 7:[7]

This shows more than just POST variables, but it's about as easy as it gets.

<?php
    phpinfo(INFO_VARIABLES);
?>

Solution 8:[8]

Besides using inline debug statements, you could also considering transient debugging, i.e. you could use an IDE with debug capabilities, like eclipse or zend studio. This way you could watch any variable you'd like to.

bye!

Solution 9:[9]

use print_r($_POST); or var_dump($_POST);
you can always display var echo command:

echo ($_POST['value']); 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paolo Bergantino
Solution 2 Community
Solution 3 Peter Mortensen
Solution 4 Whiler
Solution 5 Tim
Solution 6 Rexxars
Solution 7 Tyler Mecham
Solution 8 Hermooz
Solution 9