61 lines
2.3 KiB
PHP
Executable File
61 lines
2.3 KiB
PHP
Executable File
<?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"); ?>
|