Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q7 of 15
PHP - Superglobals and Web Context
Identify the error in this code snippet:
<?php
$name = $_GET[name];
echo $name;
?>
AVariable $name is not declared
BMissing quotes around 'name' key in $_GET
CEcho statement syntax error
DUsing $_POST instead of $_GET
Step-by-Step Solution
Solution:
  1. Step 1: Check array key syntax

    Array keys must be quoted strings in PHP, so $_GET[name] is invalid.
  2. Step 2: Correct syntax

    Use $_GET['name'] with quotes to access the key properly.
  3. Final Answer:

    Missing quotes around 'name' key in $_GET -> Option B
  4. Quick Check:

    Array keys need quotes: $_GET['name'] [OK]
Quick Trick: Always quote array keys like $_GET['key'] [OK]
Common Mistakes:
  • Omitting quotes around keys
  • Confusing $_GET with $_POST
  • Assuming variables auto-declared

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes