Bird
0
0

Identify the error in this PHP code snippet handling a POST form:

medium📝 Debug Q14 of 15
PHP - Superglobals and Web Context
Identify the error in this PHP code snippet handling a POST form:
<?php
if ($_POST['email']) {
    echo 'Email: ' . $_POST['email'];
} else {
    echo 'No email provided';
}
?>
AMissing quotes around 'email' key
BNo check if $_POST['email'] is set before use
CUsing GET method instead of POST
DIncorrect echo syntax
Step-by-Step Solution
Solution:
  1. Step 1: Analyze use of $_POST['email'] without isset

    The code accesses $_POST['email'] directly without checking if it exists, which can cause an undefined index notice if form not submitted.
  2. Step 2: Explain proper check

    Use isset($_POST['email']) to verify the key exists before accessing it.
  3. Final Answer:

    No check if $_POST['email'] is set before use -> Option B
  4. Quick Check:

    Always check isset($_POST['key']) before use [OK]
Quick Trick: Always use isset() before accessing $_POST keys [OK]
Common Mistakes:
  • Accessing $_POST keys without isset
  • Confusing POST and GET methods
  • Syntax errors in echo statement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes