Bird
0
0

What is wrong with this PHP code?

medium📝 Debug Q7 of 15
PHP - Superglobals and Web Context
What is wrong with this PHP code?
<?php
if ($_GET['id'] == 10) {
    echo 'ID is 10';
}
?>

Assuming the URL does not have an 'id' parameter.
ASyntax error in if statement
BIncorrect comparison operator
CMissing else statement
DAccessing undefined index 'id' in $_GET
Step-by-Step Solution
Solution:
  1. Step 1: Check if 'id' exists in $_GET and accessing undefined index causes notice or warning

    The URL lacks 'id', so $_GET['id'] is undefined. Directly using $_GET['id'] without checking causes an error.
  2. Final Answer:

    Accessing undefined index 'id' in $_GET -> Option D
  3. Quick Check:

    Undefined index access causes error [OK]
Quick Trick: Always check if key exists before accessing superglobals [OK]
Common Mistakes:
  • Ignoring undefined index warnings
  • Thinking comparison operator is wrong
  • Expecting else is mandatory

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes