The following files exists in this folder. Click to view.
editUser.php43 lines UTF-8 Unix (LF)
<?php
require_once "check_login.php";
require_once "database_connection.php";
$userId = (int)($_GET["userId"] ?? 0);
if ($userId < 1) {
header("Location: admin.php?mess=Felaktigt id.");
exit;
}
$sql = "SELECT userId, username, password FROM user WHERE userId=? LIMIT 1";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $userId);
$stmt->execute();
$user = $stmt->get_result()->fetch_assoc();
if (!$user) {
header("Location: admin.php?mess=Användare hittades inte.");
exit;
}
?>
<!doctype html>
<html lang="sv">
<head><meta charset="utf-8"><title>Redigera</title></head>
<body>
<h1>Uppdatera användare</h1>
<form method="post" action="updateUser.php">
<input type="hidden" name="userId" value="<?php echo (int)$user["userId"]; ?>">
<label>Användarnamn</label>
<input type="text" name="username" value="<?php echo htmlspecialchars($user["username"]); ?>" required>
<label>Lösenord</label>
<input type="text" name="password" value="<?php echo htmlspecialchars($user["password"]); ?>" required>
<button type="submit">Spara</button>
</form>
<p><a href="admin.php">Tillbaka</a></p>
</body>
</html>