Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to prepare a SQL statement.
PHP
$stmt = $conn->[1]("SELECT * FROM users WHERE id = ?");
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using query() instead of prepare() causes no placeholder support.
Trying to execute() before preparing the statement.
✗ Incorrect
The prepare method creates a prepared statement for execution.
2fill in blank
mediumComplete the code to bind a parameter to the prepared statement.
PHP
$stmt->[1]("i", $userId);
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling execute() before binding parameters.
Using fetch() instead of bind_param().
✗ Incorrect
The bind_param method binds variables to the parameter markers in the SQL statement.
3fill in blank
hardFix the error in executing the prepared statement.
PHP
$stmt->[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Calling prepare() again instead of execute().
Using query() which does not work with prepared statements.
✗ Incorrect
The execute method runs the prepared statement after binding parameters.
4fill in blank
hardFill both blanks to fetch the result from the executed statement.
PHP
$stmt->[1](); $stmt->[2]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to fetch before executing.
Not binding results before fetching data.
✗ Incorrect
First, execute() runs the statement, then bind_result() binds variables to the columns in the result set.
5fill in blank
hardFill all three blanks to complete a safe prepared statement workflow.
PHP
$stmt = $conn->[1]("SELECT name FROM users WHERE id = ?"); $stmt->[2]("i", $id); $stmt->[3]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up the order of prepare, bind_param, and execute.
Using query() instead of prepare().
✗ Incorrect
The correct order is to prepare the statement, bind parameters, then execute it.