Prepared statements use placeholders for values to be inserted. The code snippet in your question already interpolates the value into the query and is thus prone to SQL injection.
The following pseudo-code highlights prepared statements:
$stmt = $conn->prepare('SELECT * FROM `table` WHERE `id` = ?');
$stmt->execute($_POST['id']);
In this example, the logic behind this "code" would take care of properly quoting whatever is in $_POST['id']
and substituting the question mark ?
with that. You might also encounter the following placeholders:
$stmt = $conn->prepare('SELECT * FROM `table` WHERE `id` = :id');
$stmt->execute(array(
'id' => $_POST['id']
));
Note, however, that prepared statements do not relieve you of your duty to validate user-provided input before passing it along to a (My)SQL statement: if id
is expected to be an integer, only accept integers as input.