dev version 1 #1
@ -26,6 +26,6 @@
|
||||
|
||||
<nav class="navbar navbar-dark bg-dark">
|
||||
<div class="container">
|
||||
<a href="index.php" class="navbar-brand">GESTOR DATASET</a>
|
||||
<a href="/crud_php/index.php" class="navbar-brand">GESTOR DATASET</a>
|
||||
</div>
|
||||
</nav>
|
||||
@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
include("db.php");
|
||||
|
||||
// Verificar si se pasó el nombre de la tabla como parámetro
|
||||
if (!isset($_GET['table'])) {
|
||||
die("No se especificó una tabla.");
|
||||
}
|
||||
|
||||
$table_name = $_GET['table'];
|
||||
|
||||
// Validar el nombre de la tabla
|
||||
if (!preg_match('/^[a-zA-Z0-9_]+$/', $table_name)) {
|
||||
die("El nombre de la tabla contiene caracteres no permitidos.");
|
||||
}
|
||||
|
||||
if (isset($_POST['save_dataset'])) {
|
||||
$instruction = $_POST['instruction'];
|
||||
$input = $_POST['input'];
|
||||
$output = $_POST['output'];
|
||||
|
||||
$query = "INSERT INTO $table_name (instruction, input, output) VALUES ('$instruction', '$input', '$output')";
|
||||
$result = mysqli_query($conn, $query);
|
||||
|
||||
if (!$result) {
|
||||
die("Error al insertar datos: " . mysqli_error($conn));
|
||||
}
|
||||
|
||||
echo "<script>alert('Dataset guardado exitosamente.'); window.location.href = 'gestor_dataset.php?table=$table_name';</script>";
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
<?php include("includes/header.php"); ?>
|
||||
<?php include("db.php"); ?>
|
||||
<?php include("../includes/header.php"); ?>
|
||||
<?php include("../db.php"); ?>
|
||||
|
||||
<?php
|
||||
// Verificar si se pasó el nombre de la tabla como parámetro
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
include("db.php");
|
||||
include("../db.php");
|
||||
|
||||
// Verificar si se pasaron los parámetros 'table' y 'id'
|
||||
if (!isset($_GET['table']) || !isset($_GET['id'])) {
|
||||
@ -25,7 +25,7 @@ $query = "DELETE FROM $table_name WHERE id = $id";
|
||||
$result = mysqli_query($conn, $query);
|
||||
|
||||
if ($result) {
|
||||
echo "<script>alert('Registro eliminado exitosamente.'); window.location.href = 'gestor_dataset.php?table=$table_name';</script>";
|
||||
echo "<script>alert('Registro eliminado exitosamente.'); window.location.href = 'index.php?table=$table_name';</script>";
|
||||
} else {
|
||||
die("Error al eliminar el registro: " . mysqli_error($conn));
|
||||
}
|
||||
@ -1,14 +1,14 @@
|
||||
<?php
|
||||
|
||||
include("db.php");
|
||||
include("../db.php");
|
||||
|
||||
// Verificar si se pasaron los parámetros 'id' y 'table'
|
||||
if (!isset($_GET['id']) || !isset($_GET['table'])) {
|
||||
die("No se especificaron los parámetros necesarios.");
|
||||
}
|
||||
|
||||
$id = $_GET['id'];
|
||||
$table_name = $_GET['table'];
|
||||
$id = isset($_GET['id']) ? $_GET['id'] : '';
|
||||
$table_name = isset($_GET['table']) ? $_GET['table'] : '';
|
||||
|
||||
// Validar el nombre de la tabla
|
||||
if (!preg_match('/^[a-zA-Z0-9_]+$/', $table_name)) {
|
||||
@ -33,12 +33,12 @@ if (isset($_POST['update_dataset'])) {
|
||||
|
||||
$query = "UPDATE $table_name SET instruction = '$instruction', input = '$input', output = '$output' WHERE id = $id";
|
||||
mysqli_query($conn, $query);
|
||||
header("Location: gestor_dataset.php?table=$table_name");
|
||||
header("Location: index.php?table=$table_name");
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<?php include("includes/header.php"); ?>
|
||||
<?php include("../includes/header.php"); ?>
|
||||
|
||||
<div class="container p-4">
|
||||
<div class="row">
|
||||
@ -63,4 +63,4 @@ if (isset($_POST['update_dataset'])) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include("includes/footer.php"); ?>
|
||||
<?php include("../includes/footer.php"); ?>
|
||||
@ -1,3 +1,10 @@
|
||||
<?php
|
||||
include("../includes/header.php");
|
||||
|
||||
// Obtener el nombre de la tabla desde la URL
|
||||
$table = isset($_GET['table']) ? $_GET['table'] : '';
|
||||
?>
|
||||
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
|
||||
@ -22,6 +29,11 @@
|
||||
<h1 align="center" style="color:color(srgb 0.52 0.59 0.7);font-weight:bold;">Datatables server side processing with PHP and MYSQL </h1>
|
||||
<br>
|
||||
<div class="container">
|
||||
<div class="mb-3">
|
||||
<a href="add_dataset.php?table=<?php echo htmlspecialchars($table); ?>" class="btn btn-primary">
|
||||
<i class="bi bi-plus-circle"></i> Agregar Dataset
|
||||
</a>
|
||||
</div>
|
||||
<table id="example" class="display" style="width:100%">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -53,28 +65,28 @@
|
||||
"table": "<?php echo htmlspecialchars($_GET['table']); ?>" // Pasar el nombre de la tabla
|
||||
}
|
||||
},
|
||||
/*"columns": [{
|
||||
"data": "instruction"
|
||||
"columns": [{
|
||||
data: 0
|
||||
},
|
||||
{
|
||||
"data": "input"
|
||||
data: 1
|
||||
},
|
||||
{
|
||||
"data": "output"
|
||||
data: 2
|
||||
},
|
||||
{
|
||||
"data": "created_ad"
|
||||
data: 3
|
||||
},
|
||||
{
|
||||
"data": "id",
|
||||
data: 4,
|
||||
"render": function(data, type, row) {
|
||||
return `
|
||||
<a href="edit.php?table=<?php echo htmlspecialchars($_GET['table']); ?>&id=${data}" class="btn btn-secondary m-2">Editar</a>
|
||||
<a href="delete.php?table=<?php echo htmlspecialchars($_GET['table']); ?>&id=${data}" class="btn btn-danger" onclick="return confirm('¿Estás seguro de que deseas eliminar este registro?');">Eliminar</a>
|
||||
<a href="delete_dataset.php?table=<?php echo htmlspecialchars($_GET['table']); ?>&id=${data}" class="btn btn-danger" onclick="return confirm('¿Estás seguro de que deseas eliminar este registro?');">Eliminar</a>
|
||||
`;
|
||||
}
|
||||
}
|
||||
]*/
|
||||
]
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
61
server_side/save_dataset.php
Executable file
61
server_side/save_dataset.php
Executable file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
include("../db.php");
|
||||
|
||||
// Verificar si se pasó el nombre de la tabla como parámetro
|
||||
if (!isset($_GET['table'])) {
|
||||
die("No se especificó una tabla.");
|
||||
}
|
||||
|
||||
$table_name = $_GET['table'];
|
||||
|
||||
// Validar el nombre de la tabla
|
||||
if (!preg_match('/^[a-zA-Z0-9_]+$/', $table_name)) {
|
||||
die("El nombre de la tabla contiene caracteres no permitidos.");
|
||||
}
|
||||
|
||||
// Procesar el formulario si se envió
|
||||
if (isset($_POST['save_dataset'])) {
|
||||
// Escapar las entradas para prevenir SQL Injection
|
||||
$instruction = mysqli_real_escape_string($conn, $_POST['instruction']);
|
||||
$input = mysqli_real_escape_string($conn, $_POST['input']);
|
||||
$output = mysqli_real_escape_string($conn, $_POST['output']);
|
||||
|
||||
$query = "INSERT INTO `$table_name` (instruction, input, output) VALUES ('$instruction', '$input', '$output')";
|
||||
$result = mysqli_query($conn, $query);
|
||||
|
||||
if (!$result) {
|
||||
die("Error al insertar datos: " . mysqli_error($conn));
|
||||
}
|
||||
|
||||
echo "<script>alert('Dataset guardado exitosamente.'); window.location.href = 'index.php?table=$table_name';</script>";
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<?php include("../includes/header.php"); ?>
|
||||
|
||||
<div class="container p-4">
|
||||
<div class="row">
|
||||
<div class="col-md-6 mx-auto">
|
||||
<div class="card card-body">
|
||||
<h5 class="text-center">Agregar Dataset a la tabla: <?php echo htmlspecialchars($table_name); ?></h5>
|
||||
<form action="save_dataset.php?table=<?php echo urlencode($table_name); ?>" method="POST">
|
||||
<div class="form-group mb-3">
|
||||
<input type="text" name="instruction" class="form-control" placeholder="Instruction" autofocus required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<input type="text" name="input" class="form-control" placeholder="Input" required>
|
||||
</div>
|
||||
<div class="form-group mb-3">
|
||||
<textarea name="output" rows="2" class="form-control" placeholder="Output" required></textarea>
|
||||
</div>
|
||||
<div class="d-grid">
|
||||
<input type="submit" name="save_dataset" class="btn btn-success" value="Guardar Dataset">
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php include("../includes/footer.php"); ?>
|
||||
Loading…
x
Reference in New Issue
Block a user