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
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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.