View sourcecode

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

insertUser.php

22 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
<?php
require_once "check_login.php";
require_once 
"database_connection.php";

$username trim($_POST["username"] ?? "");
$password trim($_POST["password"] ?? "");

if (
$username === "" || $password === "") {
  
header("Location: addUser.php?mess=Tomma fält är inte tillåtna.");
  exit;
}

$sql "INSERT INTO user (username, password) VALUES (?, ?)";
$stmt $conn->prepare($sql);
$stmt->bind_param("ss"$username$password);
$stmt->execute();

$newId $conn->insert_id;

header("Location: admin.php?mess=Användare skapad (id {$newId}).");
exit;