Challenge - 5 Problems
Post Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this PHP code using $_POST?
Consider a form submission where the form sends a POST request with a field named 'username' set to 'Alice'. What will this PHP code output?
PHP
<?php if (isset($_POST['username'])) { echo "Hello, " . $_POST['username'] . "!"; } else { echo "No username provided."; } ?>
Attempts:
2 left
💡 Hint
Remember that $_POST contains data sent by the form using the POST method.
✗ Incorrect
If the form sends 'username' with value 'Alice', then $_POST['username'] is set and the code prints 'Hello, Alice!'.
🧠 Conceptual
intermediate1:30remaining
Which statement about $_POST is true?
Choose the correct statement about the PHP $_POST superglobal array.
Attempts:
2 left
💡 Hint
Think about how form data is sent using different HTTP methods.
✗ Incorrect
$_POST is an associative array that holds data sent by forms using the POST method.
🔧 Debug
advanced2:00remaining
Why does this PHP code produce an error when accessing $_POST?
What error will this code produce and why?
PHP
<?php echo $_POST['email']; ?>
Attempts:
2 left
💡 Hint
What happens if you try to access an array key that does not exist?
✗ Incorrect
Accessing $_POST['email'] when 'email' is not sent causes a PHP notice: Undefined index.
📝 Syntax
advanced2:30remaining
Which option correctly checks if a POST field 'age' is set and not empty?
Select the correct PHP code snippet that safely checks if the 'age' field was submitted and is not empty.
Attempts:
2 left
💡 Hint
Use isset() to check if the key exists and compare to empty string to ensure it's not empty.
✗ Incorrect
Option B correctly uses isset() to check existence and compares to empty string to ensure value is not empty.
🚀 Application
expert3:00remaining
How many items are in $_POST after submitting this form?
Given this HTML form submitted via POST:
How many key-value pairs will $_POST contain after submission?
How many key-value pairs will $_POST contain after submission?
Attempts:
2 left
💡 Hint
Checkboxes only send their value if checked. Multiple inputs with the same name overwrite or combine values.
✗ Incorrect
Only 'first', 'last', and 'subscribe' fields are sent. Since only one 'subscribe' checkbox is checked, $_POST has keys 'first', 'last', and 'subscribe'. So 3 keys. But since 'subscribe' checkboxes share the same name, only one value is sent for 'subscribe'. So total keys: 3.