View sourcecode

The following files exists in this folder. Click to view.

editUser.php

43 lines UTF-8 Unix (LF)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?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>