<?php
header('Content-Type: application/json');

// Database connection
$servername = "sql.freedb.tech";
$username = "freedb_dexterso_adhd_ln";
$password = "M-L8ehOLaFOm";
$dbname = "freedb_dexterso_adhd_app";

$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die(json_encode(['success' => false, 'message' => 'Database connection failed.']));
}

// Get data from POST request
$email = $_POST['email'];
$password = $_POST['password'];
$google_email = $_POST['google_email'];
$role = $_POST['role'];
$grade = $_POST['grade'];
$stream_details  = $_POST['stream_details'];

// Insert into database
$sql = "INSERT INTO tbl_adhd_users (email, password, google_email, role, grade, stream_details ) VALUES (?, ?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param("ssssss", $email, $password, $google_email, $role, $grade, $stream_details);

if ($stmt->execute()) {
    echo json_encode(['success' => true, 'message' => 'Account created successfully.']);
} else {
    echo json_encode(['success' => false, 'message' => 'Error creating account.']);
}

$stmt->close();
$conn->close();
?>