Fix SQL injection in the rest of the passman

This commit is contained in:
2026-01-11 16:48:48 +02:00
parent f94a1ebbd5
commit bd9aec48d7
3 changed files with 76 additions and 21 deletions
+17 -6
View File
@@ -50,13 +50,24 @@ if(isset($_POST['new_note']) && trim($_POST['new_note']) !='') {
//$sql_query = "INSERT INTO notes (login_user_id,note) VALUES " .
// "((SELECT id FROM login_users WHERE username='{$username}'),('{$new_note}'));";
$sql_query = "INSERT INTO notes (login_user_id, note) ".
"VALUES ((SELECT id FROM login_users WHERE username='{$username}'), '{$new_note}')";
// Insert new note using a prepared statement to prevent SQL injection.
$sql_query = "INSERT INTO notes (login_user_id, note) ".
"VALUES ((SELECT id FROM login_users WHERE username = ?), ?)";
$stmt = $conn->prepare($sql_query);
if ($stmt === false) {
// Fail closed (do not leak DB details).
$conn->close();
die("Prepare failed.");
}
$stmt->bind_param("ss", $username, $new_note);
//echo $sql_query;
$result = $stmt->execute();
$stmt->close();
$conn->close();
//echo $sql_query;
$result = $conn->query($sql_query);
$conn -> close();
// After processing, redirect to the same page to clear the form
unset($_POST['new_note']);