-
Notifications
You must be signed in to change notification settings - Fork 0
/
editar.php
27 lines (27 loc) · 940 Bytes
/
editar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
if (isset($_POST['data'])) {
error_log("Datos recibidos: " . $_POST['data']);
$data = json_decode($_POST['data'], true);
$index = $data['index'];
$newData = $data['newData'];
$file = fopen('datos.csv', 'r');
$rows = array();
while (($row = fgetcsv($file)) !== false) {
$rows[] = $row;
}
fclose($file);
if (isset($rows[$index])) {
error_log("Actualizando fila " . $index . " con nuevos datos: " . implode(",", $newData));
$rows[$index] = $newData;
$file = fopen('datos.csv', 'w');
foreach ($rows as $row) {
fputcsv($file, $row);
}
fclose($file);
} else {
error_log("Índice " . $index . " no encontrado en el archivo de datos");
}
} else {
error_log("No se recibieron datos");
}
?>