GeekInterview.com
Series: Subject: Topic:
Question: 1 of 98

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??
Asked by: Interview Candidate | Asked on: Nov 12th, 2011
Showing Answers 1 - 5 of 5 Answers
Faisal Jamil

Answered On : 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>

Yes  1 User has rated as useful.
  
Login to rate this answer.
Tim Huff

Answered On : 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";

Yes  2 Users have rated as useful.
  
Login to rate this answer.
Karthick

Answered On : Apr 28th, 2012

use $_REQUEST

Code
  1. <?php
  2.  
  3. foreach ( $_REQUEST as $key => $value )
  4. {
  5.   echo "$key : $value <br>";
  6. }
  7.  
  8. ?>

Yes  1 User has rated as useful.
  
Login to rate this answer.

Code
  1. <?php
  2. echo "Post data: ";
  3. foreach ($_GET as $key => $value)
  4. {
  5. print_r($key , $value);
  6. }
  7. ?>

  
Login to rate this answer.
tdka14

Answered On : Dec 3rd, 2012

View all answers by tdka14

Code
  1. <?php
  2. echo '<pre>';
  3. print_r($_REQUEST);
  4. echo '</pre>';
  5.  

  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.