chrisdee wrote:So if I understand correctly sanitation my inputs would mean escaping my variables against special characters with mysqli_real_escape_string like I do below?
mysqli_real_escape_string is appropriate for strings but for other types you should cast appropriately. Furthermore, you should check that those incoming variables exist before using them, e.g.,
if (isset($_POST['id'], $_POST['navn'], $_POST['fra'], $_POST['til'])) {
$sql = sprintf(
"UPDATE laptop SET navn='%s', fra='%s', til='%s' WHERE id=%d",
mysqli_real_escape_string($link, $_POST['navn']),
mysqli_real_escape_string($link, $_POST['fra']),
mysqli_real_escape_string($link, $_POST['til']),
$_POST['id']
);
mysqli_query($link, $sql);
// ...
}
Actually, better than sprintf + mysqli_real_escape_string would be the use of a prepared statement with parameter bindings:
$stmt = $link->prepare("UPDATE laptop SET navn=?, fra=?, til=? WHERE id=?");
$stmt->bind_param('sssi', $_POST['navn'], $_POST['fra'], $_POST['til'], $_POST['id']);
$stmt->execute();
(I switched to the "object oriented" interface as I feel that the syntactic sugar makes it more pleasant.)