<?php
require_once dirname(__DIR__) . '/auth_check.php';
require_once dirname(__DIR__) . '/config.php';

$username = isset($_POST['username']) ? mysqli_real_escape_string($koneksi, trim($_POST['username'])) : '';
$email    = isset($_POST['email'])    ? mysqli_real_escape_string($koneksi, trim($_POST['email']))    : '';
$password = isset($_POST['password']) ? mysqli_real_escape_string($koneksi, trim($_POST['password'])) : '';
$cr       = isset($_POST['cr'])       ? (int)$_POST['cr'] : 0;
$expired  = isset($_POST['expired'])  ? mysqli_real_escape_string($koneksi, trim($_POST['expired'])) : '';
$hwid     = isset($_POST['hwid'])     ? mysqli_real_escape_string($koneksi, trim($_POST['hwid']))    : '';

if ($username === '' || $email === '' || $password === '' || $expired === '') {
    echo "error: Missing required fields"; die();
}

$date = date('Y-m-d H:i:s');
$sql = "INSERT INTO user_id (username, email, password, cr, hwid, expired, status, time) VALUES ('$username','$email','$password',$cr,'$hwid','$expired','Active','$date')";
if (mysqli_query($koneksi, $sql)) {
    echo "success";
} else {
    echo "error: " . mysqli_error($koneksi);
}
