0
0
PHPprogramming~20 mins

$_POST for form submissions in PHP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Post Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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.";
}
?>
AUndefined index: username
BNo username provided.
CHello, !
DHello, Alice!
Attempts:
2 left
💡 Hint
Remember that $_POST contains data sent by the form using the POST method.
🧠 Conceptual
intermediate
1:30remaining
Which statement about $_POST is true?
Choose the correct statement about the PHP $_POST superglobal array.
A$_POST contains data sent via the HTTP POST method.
B$_POST contains data sent via the HTTP GET method.
C$_POST is used to store session variables.
D$_POST is an object that holds form data.
Attempts:
2 left
💡 Hint
Think about how form data is sent using different HTTP methods.
🔧 Debug
advanced
2: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'];
?>
ASyntax error because $_POST is not defined.
BFatal error: Cannot access $_POST directly.
CUndefined index: email if the form did not send 'email'.
DNo output because $_POST is empty but no error.
Attempts:
2 left
💡 Hint
What happens if you try to access an array key that does not exist?
📝 Syntax
advanced
2: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.
Aif (isset($_POST['age']) || $_POST['age'] != '') { echo 'Age is set'; }
Bif (isset($_POST['age']) && $_POST['age'] !== '') { echo 'Age is set'; }
Cif ($_POST['age']) { echo 'Age is set'; }
Dif (!empty($_POST['age'])) { echo 'Age is set'; } else { echo 'Age not set'; }
Attempts:
2 left
💡 Hint
Use isset() to check if the key exists and compare to empty string to ensure it's not empty.
🚀 Application
expert
3: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?
A1
B3
C2
D0
Attempts:
2 left
💡 Hint
Checkboxes only send their value if checked. Multiple inputs with the same name overwrite or combine values.