0) { // If a bar tab already exists for this user_id, return an error message echo json_encode(['status' => 'error', 'message' => 'A bar tab already exists for this user.']); } else { // Prepare the SQL query to insert a new record into the bar_tabs table $sql = "INSERT INTO bar_tabs (user_id) VALUES ('$user_id')"; // Execute the query if (mysqli_query($conn, $sql)) { // If the insertion is successful, return a success message echo json_encode(['status' => 'success', 'message' => 'Bar tab created successfully.']); } else { // If there's an error, return an error message echo json_encode(['status' => 'error', 'message' => 'Error: ' . mysqli_error($conn)]); } } } else { // If user_id is not provided, return an error message echo json_encode(['status' => 'error', 'message' => 'User ID is required.']); } // Close the database connection mysqli_close($conn); ?>