my code looks like this (just a example, at a few parts of my projekt there are a lot of variables more then in this example):
$pdo = new PDO('mysql:host=localhost;dbname=nameofdb;charset=utf8','dbuser','dbpass');
$surname = htmlspecialchars($_POST["surname"]);
$lastname = htmlspecialchars($_POST["lastname"]);
$street = htmlspecialchars($_POST["street"]);
$username = htmlspecialchars($_POST["username"]);
$sql = $pdo->prepare("UPDATE customer SET surname = ?,lastname = ?,street = ? WHERE username = ?");
$sql->execute(array($surname, $lastname, $street,$username));
$pdo->close();
$sql->close();
All POST variables come from forms that users can(must) fill out, so it is important that it is as safe as possible.
Sorry for this (maybe) beginner question(s), but i'm new in the PDO game, still read a lot but want to see what you people say to that code.
Please tell me what i can optimize, and above all WHY, so i can learn!