dev version 1 #1
14
index.php
14
index.php
@ -6,7 +6,7 @@
|
||||
<!-- Listar tablas existentes -->
|
||||
<div class="col-md-8">
|
||||
<h5 class="text-center">Tablas Existentes</h5>
|
||||
<table class="table table-bordered">
|
||||
<table id="tables-list" class="table table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nombre de la Tabla</th>
|
||||
@ -27,8 +27,9 @@
|
||||
<td>
|
||||
<!-- Enlace para editar datasets en la tabla -->
|
||||
<a href="server_side/index.php?table=<?php echo $table_name; ?>" class="btn btn-primary">
|
||||
Editar
|
||||
Editar Contenido
|
||||
</a>
|
||||
<a href="rename_table.php?table=<?php echo $table_name; ?>" class="btn btn-warning">Renombrar</a>
|
||||
<!-- Enlace para eliminar la tabla -->
|
||||
<a href="delete_table.php?table=<?php echo $table_name; ?>" class="btn btn-danger" onclick="return confirm('¿Estás seguro de que deseas eliminar esta tabla?');">
|
||||
Eliminar
|
||||
@ -36,6 +37,15 @@
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
$('#tables-list').DataTable({
|
||||
"language": {
|
||||
"url": "https://cdn.datatables.net/plug-ins/2.3.0/i18n/es-ES.json"
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
43
rename_table.php
Normal file
43
rename_table.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?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"); ?>
|
||||
@ -109,7 +109,10 @@ $table = isset($_GET['table']) ? $_GET['table'] : '';
|
||||
`;
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"language": {
|
||||
"url": "https://cdn.datatables.net/plug-ins/2.3.0/i18n/es-ES.json"
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user