Bird
0
0

What will be the output of this PHP code if a form sends username=alice via POST?

medium📝 Predict Output Q4 of 15
PHP - Superglobals and Web Context
What will be the output of this PHP code if a form sends username=alice via POST?
<?php
echo 'Hello, ' . $_POST['username'];
?>
AHello, alice
BHello, $_POST['username']
CHello,
DError: Undefined index
Step-by-Step Solution
Solution:
  1. Step 1: Understand the code output

    The code concatenates 'Hello, ' with the value of $_POST['username'].
  2. Step 2: Check the POST data

    The form sends username=alice, so $_POST['username'] is 'alice'.
  3. Final Answer:

    Hello, alice -> Option A
  4. Quick Check:

    $_POST['username'] = alice, output = Hello, alice [OK]
Quick Trick: Echo $_POST['field'] to display submitted form data [OK]
Common Mistakes:
  • Not sending POST data causes undefined index error
  • Using single quotes around $_POST['username'] in echo
  • Confusing $_POST with $_GET

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes