<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
header("Access-Control-Allow-Methods: POST");

$host = "localhost"; // genelde localhost olur
$user = "wanywebc_baski"; // cPanel MySQL kullanıcın
$pass = "Adgebs123.";         // MySQL şifren
$db   = "wanywebc_baski"; // MySQL veritabanı adın

$conn = new mysqli($host, $user, $pass, $db);

if ($conn->connect_error) {
    echo json_encode(["success" => false, "message" => "Veritabanı bağlantı hatası"]);
    exit;
}

$data = json_decode(file_get_contents("php://input"), true);
$email = $conn->real_escape_string($data["email"]);
$password = $conn->real_escape_string($data["password"]);
$role = $data["isSeller"] ? "satici" : "alici";

$sql = "INSERT INTO kullanicilar (email, sifre, rol) VALUES ('$email', '$password', '$role')";

if ($conn->query($sql)) {
    echo json_encode(["success" => true]);
} else {
    echo json_encode(["success" => false, "message" => $conn->error]);
}

$conn->close();
?>
