Victor Bjelkholm
Victor Bjelkholm

Reputation: 2016

Echo an $_POST in PHP

How can I print a $_POST?

Example:

echo $_POST['data'];

This returns nothing...

Upvotes: 12

Views: 93254

Answers (3)

Jamex
Jamex

Reputation: 742

You can also wrap your code with <pre> tags to make your array prints out nicer instead of just 1 continuous line. A trick that was shown by a member on this site.

<pre>
<?php var_dump($_POST); ?>
</pre>

Upvotes: 22

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799150

You can only show the values of keys that exist. array_keys() returns an array containing the keys that exist in the array. If there is no output for a key despite the fact that the key exists then the array may contain an empty value for that key.

Upvotes: 2

Tim Ridgely
Tim Ridgely

Reputation: 2420

Your code is correct.

You can use either:

var_dump($_POST);

or

print_r($_POST);

to print out the entire POST array for debugging.

Upvotes: 8

Related Questions