B. php / pasatiempo-agrega.php

1
<?php
2
3
require_once __DIR__ . "/lib/manejaErrores.php";
4
require_once __DIR__ . "/lib/recibeTextoObligatorio.php";
5
require_once __DIR__ . "/lib/devuelveCreated.php";
6
require_once __DIR__ . "/Bd.php";
7
8
$nombre = recibeTextoObligatorio("nombre");
9
10
$bd = Bd::pdo();
11
$stmt = $bd->prepare(
12
 "INSERT INTO PASATIEMPO (
13
    PAS_NOMBRE
14
   ) values (
15
    :PAS_NOMBRE
16
   )"
17
);
18
$stmt->execute([
19
 ":PAS_NOMBRE" => $nombre
20
]);
21
$id = $bd->lastInsertId();
22
23
$encodeId = urlencode($id);
24
devuelveCreated(
25
 "/php/pasatiempo-vista-modifica.php?id=$encodeId",
26
 [
27
  "id" => ["value" => $id],
28
  "nombre" => ["value" => $nombre],
29
 ]
30
);
31
skip_previous skip_next