Php fragment

1- Write php fragment code to print out the data submitted by the user through html form using get or post method? we need to display the field name and value??

Showing Answers 1 - 5 of 5 Answers

Faisal Jamil

  • Dec 27th, 2011
 

Code
  1. <?php

  2.  

  3. foreach ( $_GET as $key => $value )

  4. {

  5.   echo "$key : $value <br>";

  6. }

  7.  

  8. ?>


Same code works equally for $_POST, depending on the method of HTML form. e.g.

Code
  1. <form action="" method="get">

  2.  

  3. <input name="username" type="text" />

  4. <input name="password" type="text" />

  5. <input type="submit"/>

  6.  

  7. </form>

Tim Huff

  • Jan 31st, 2012
 

Just iterate across the POST and GET globals

Code
  1. echo "Post data:

  2. ";

  3. foreach($_POST as $key=>$value)

  4.   echo "$key:$value

  5. ";

  6. echo "Get data:

  7. ";

  8. foreach($_GET as $key=>$value)

  9.   echo "$key:$value";

Karthick

  • Apr 28th, 2012
 

Use $_REQUEST

Code
  1. <?php

  2.  

  3. foreach ( $_REQUEST as $key => $value )

  4. {

  5.   echo "$key : $value <br>";

  6. }

  7.  

  8. ?>

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions