DIDS-Coursework/DIS-COMP4039-CW2-psxrp11-20450011/psxrp11-20450011_InstallationFiles/newUser.php

29 lines
882 B
PHP
Raw Normal View History

<?php
session_start();
require_once 'config.php';
header('Content-Type: application/json');
if (isset($_SESSION["username"]) && isset($_SESSION["admin"]))
{
$username = $_POST["username"];
$password = $_POST["password"];
$admin = $_POST["admin"];
$conn = dbConn();
$stmt = $conn->prepare("INSERT INTO Users (Users_username, Users_password, Users_admin) VALUES (:username, :password, :admin)");
$stmt->bindParam(":username", $username);
$stmt->bindParam(":password", $password);
$isAdmin = $admin ? 1 : 0;
$stmt->bindParam(":admin", $isAdmin);
$stmt->execute();
echo json_encode(array("message" => "ok", "admin" => $admin));
}
else if (isset($_SESSION["username"]) && !isset($_SESSION["admin"]))
{
echo json_encode(array("message" => "not logged in as admin"));
}
else
{
echo json_encode(array("message" => "Not logged in "));
}