<?php
require_once "labClass.php";
$con = new labClass();

if (isset($_POST['submit'])) {
     $user = trim($_POST['user']);
    $username = trim($_POST['username']);
    $password = trim($_POST['password']);

    if ($username === '') {
        echo "<span class='text-danger'>All fields are required!</span>";
        exit;
    }

    // Hash password 
 
    try {
        $stmt = $con->registerU($user, $username, $password);

        echo "<span class='text-success'>User registered successfully!</span>";
        require_once "secretinfoRstff.php";
      } catch (PDOException $e) {
        if ($e->getCode() == 23000) {
            echo "<span class='text-danger'>Username already exists!</span>";
        } else {
            echo "<span class='text-danger'>Error: " . htmlspecialchars($e->getMessage()) . "</span>";
            require_once "secretinfoRstff.php";
        }
    }
}
?>
