gestor_dataset/rename_table.php
2025-06-27 12:53:02 -04:00

43 lines
1.5 KiB
PHP

<?php
include("includes/header.php");
include("db.php");
if (!isset($_GET['table'])) {
die("No se especificó la tabla.");
}
$old_table = $_GET['table'];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$new_table = $_POST['new_table'];
if (preg_match('/^[a-zA-Z0-9_]+$/', $new_table)) {
$sql = "RENAME TABLE `$old_table` TO `$new_table`";
if (mysqli_query($conn, $sql)) {
echo "<script>alert('Tabla renombrada correctamente');window.location='index.php';</script>";
exit;
} else {
echo "<div class='alert alert-danger'>Error: " . mysqli_error($conn) . "</div>";
}
} else {
echo "<div class='alert alert-danger'>Nombre de tabla no válido.</div>";
}
}
?>
<div class="container p-4">
<div class="row">
<div class="col-md-6 mx-auto">
<div class="card card-body">
<h5 class="text-center">Renombrar tabla: <?php echo htmlspecialchars($old_table); ?></h5>
<form method="POST">
<div class="form-group mb-3">
<input type="text" name="new_table" class="form-control" placeholder="Nuevo nombre de la tabla" required>
</div>
<div class="d-grid">
<button type="submit" class="btn btn-warning">Renombrar</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php include("includes/footer.php"); ?>