connect_error) {
die("Connection error: " . $conn->connect_error);
}
// Variable to store results and errors
$resultMessage = '';
$tableOutput = '';
// Form handling
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$query = $_POST['sql_query'] ?? '';
if (!empty($query)) {
if ($result = $conn->query($query)) {
if ($result instanceof mysqli_result) {
// Create a table with the results
$tableOutput .= "
";
while ($fieldinfo = $result->fetch_field()) {
$tableOutput .= "| {$fieldinfo->name} | ";
}
$tableOutput .= "
";
while ($row = $result->fetch_assoc()) {
$tableOutput .= "";
foreach ($row as $cell) {
// Safe value processing (null -> empty string)
$tableOutput .= "| " . htmlspecialchars($cell ?? '') . " | ";
}
$tableOutput .= "
";
}
$tableOutput .= "
";
$result->free();
} else {
$resultMessage = "Request executed successfully."
}
} else {
$resultMessage = "Query error: " . $conn->error;
}
} else {
$resultMessage = "Query field cannot be empty."
}
}
$conn->close();
?>
Shop base preview
Base preview Shop
Only SELECT queries can be performed here
$resultMessage"; ?>
= $tableOutput ?>
Kod tej aplikacji jest dostępny tutaj