<?php
// Include database connection
require_once('connectionSC.php');

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Get data from POST request
    $username = $_POST['username'];
    $password = $_POST['password'];
    $hashedPassword = md5($password);  // MD5 hash
    $akses_level = $_POST['akses_level'];
    $cabang = $_POST['cabang'];

    // SQL query to insert data
    $sql = "INSERT INTO `admin` (`nama`, `email`, `username`, `password`, `akses_level`, `cabang`, `tanggal_input`) 
            VALUES ('$username', '-', '$username', '$hashedPassword', '$akses_level', '$cabang', NOW())";
    
    // Execute query
    if (mysqli_query($conn, $sql)) {
        echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . mysqli_error($conn);
    }
}

// Close connection
mysqli_close($conn);
?>
