| 1 | <?php |
| 2 | |
| 3 | require_once __DIR__ . "/lib/manejaErrores.php"; |
| 4 | require_once __DIR__ . "/lib/recibeEntero.php"; |
| 5 | require_once __DIR__ . "/lib/recibeTextoObligatorio.php"; |
| 6 | require_once __DIR__ . "/lib/recibeEnteroOpcional.php"; |
| 7 | require_once __DIR__ . "/lib/devuelveCreated.php"; |
| 8 | require_once __DIR__ . "/Bd.php"; |
| 9 | require_once __DIR__ . "/pasatiempoOptions.php"; |
| 10 | |
| 11 | $nombre = recibeTextoObligatorio("nombre"); |
| 12 | $pasId = recibeEnteroOpcional("pasId"); |
| 13 | |
| 14 | $pdo = Bd::pdo(); |
| 15 | $stmt = $pdo->prepare( |
| 16 | "INSERT INTO AMIGO ( |
| 17 | AMI_NOMBRE, PAS_ID |
| 18 | ) values ( |
| 19 | :PAS_NOMBRE, :PAS_ID |
| 20 | )" |
| 21 | ); |
| 22 | $stmt->execute([ |
| 23 | ":PAS_NOMBRE" => $nombre, |
| 24 | ":PAS_ID" => $pasId |
| 25 | ]); |
| 26 | $id = $pdo->lastInsertId(); |
| 27 | |
| 28 | $encodeId = urlencode($id); |
| 29 | devuelveCreated( |
| 30 | "/php/amigo-vista-modifica.php?id=$encodeId", |
| 31 | [ |
| 32 | "id" => ["value" => $id], |
| 33 | "nombre" => ["value" => $nombre], |
| 34 | "pasId" => [ |
| 35 | "innerHTML" => pasatiempoOptons(), |
| 36 | "value" => $pasId === null ? "" : $pasId |
| 37 | ] |
| 38 | ] |
| 39 | ); |
| 40 | |