<?php
session_start();
include 'db.php'; // Must define $conn = new mysqli(...)

$message = "";

// --- REGISTER ---
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['register'])) {
    $fullname = trim($_POST['fullname']);
    $mobile   = trim($_POST['mobile']);
    $email    = trim($_POST['email']);
    $place    = trim($_POST['place']);
   

    // Check duplicate mobile
    $check = $conn->prepare("SELECT id FROM usermaster WHERE mobile=?");
    $check->bind_param("s", $mobile);
    $check->execute();
    $check->store_result();

    if ($check->num_rows > 0) {
        $message = "<div class='alert alert-danger'>Mobile already registered.</div>";
    } else {
        $stmt = $conn->prepare("INSERT INTO usermaster (fullname, mobile, email, place ) VALUES (?,?,?,?)");
        $stmt->bind_param("ssssss", $fullname, $mobile, $email, $place);
        if ($stmt->execute()) {
            $message = "<div class='alert alert-success'>Registration successful! Please login.</div>";
        } else {
            $message = "<div class='alert alert-danger'>Registration failed!</div>";
        }
    }
}

?>
 