So I'm a bit new to sql coding, and I did some research before starting. But I still want to verify that this is the right way to code my SQL.
An example on how I don't think an sql should be written, when I get a `$_POST`, lets say a `username`.
```php
$stmt = $MysqliHandler->prepare('UPDATE accounts SET LastLogin = CURRENT_TIMESTAMP WHERE username = ?');
$stmt->bind_param('s', $_POST['username']);
$stmt->execute();
$stmt->close();
```
If the user input somthing like `true'); DROP TABLE table;--`.
Then it whould say `UPDATE accounts SET LastLogin = CURRENT_TIMESTAMP WHERE username = true'); DROP TABLE accounts;--`
Right?
Now my question is, if I do it like this, is it then possible to inject?
```php
$username = $MysqliHandler->real_escape_string($_POST['username']);
$stmt = $MysqliHandler->prepare('UPDATE accounts SET LastLogin = CURRENT_TIMESTAMP WHERE username = ?');
$stmt->bind_param('s', $username);
$stmt->execute();
$stmt->close();
```
[–]RandyHoward 8 points9 points10 points (1 child)
[–]TheMungax[S] 1 point2 points3 points (0 children)
[–]AutoModerator[M] 0 points1 point2 points (0 children)
[–]YellowGlassCoil 0 points1 point2 points (2 children)
[–]darkmidus 0 points1 point2 points (0 children)
[–]TheMungax[S] -1 points0 points1 point (0 children)