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

// Database connection parameters
$servername = "localhost";
$username = "venmobdc_Auto_DataBase_User";
$password = "hB_nf_W-^SIh";
$dbname = "venmobdc_Auto_Database";

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

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

// Get the table name from POST request
$tableName = isset($_POST['tableName']) ? $_POST['tableName'] : '';

if ($tableName) {
    // Escape the table name for use in SQL query
    $tableName = $conn->real_escape_string($tableName);

    // Debugging: Log the table name
    error_log("Table name: " . $tableName);

    // Use backticks to escape table names
    $sql = "SHOW TABLES LIKE '$tableName'";
    $result = $conn->query($sql);

    if ($result && $result->num_rows > 0) {
        echo json_encode("exists");
    } else {
        echo json_encode("not_exists");
    }
} else {
    echo json_encode("error");
}

$conn->close();
?>
