Jump to content

tip of the day: printpost.php


andrewgauger

Recommended Posts

put a file in your script directory named printpost.php with this code:

 

<?php
foreach ($_POST as $key => $arg){
print $key. " = ". $arg. "<br>";}
?>

once you create your form, start with <form method="post" action="printpost.php"> ... </form>

 

This will help you make sure you have the data you were expecting from the form BEFORE you start coding the handler that way you can rule out bad data as a source of unexpected results.

 

Please reply with any good tips  :D

Link to comment
https://forums.phpfreaks.com/topic/196679-tip-of-the-day-printpostphp/
Share on other sites

put a file in your script directory named printpost.php with this code:

 

<?php
foreach ($_POST as $key => $arg){
print $key. " = ". $arg. "<br>";}
?>

once you create your form, start with <form method="post" action="printpost.php"> ... </form>

 

This will help you make sure you have the data you were expecting from the form BEFORE you start coding the handler that way you can rule out bad data as a source of unexpected results.

 

Please reply with any good tips  :D

 

Whats wrong with?

 

<pre>
<?php print_r($_REQUEST); ?>
</pre>

I love the simplicity of print_r but hate the fact it doesn't break elements into individual lines....

 

You are right that I should be parsing the $_REQUEST variable instead, should look like:

 

<?php
foreach ($_REQUEST as $key => $arg){
print $key. " = ". $arg. "<br>";}
?>

 

Maybe include an

echo $_SERVER['HTTP_REFERER'];

and execute the script with default values and print out a copy for reference.

OK, here's the thing.  I use print_r for inline debugging but I think this example goes beyond that.  What I am trying to achieve is a pleasing output that will help catch errors and it is my humble opinion that line delimitation is easier to catch errors in request variables and their values. 

OK, here's the thing.  I use print_r for inline debugging but I think this example goes beyond that.  What I am trying to achieve is a pleasing output that will help catch errors and it is my humble opinion that line delimitation is easier to catch errors in request variables and their values. 

 

It outputs newlines, thus this will work:

print nl2br(print_r($_REQUEST, 1));

 

Anything more fancy than that in a programmers perspective is pointless.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.