Guest User

Untitled

a guest
Dec 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. CREATE TABLE `valor`.`prueba` ( `documento` INT(15) NOT NULL , `nombre` VARCHAR(50) NOT NULL ) ENGINE = InnoDB;
  2.  
  3. <?php
  4.  
  5. require_once "controlador.php";
  6. require_once "modelo.php";
  7.  
  8. ?>
  9.  
  10. <!DOCTYPE html>
  11. <html>
  12. <head>
  13. <title></title>
  14. </head>
  15. <body>
  16. <form role="form" method="post">
  17. <table>
  18. <thead>
  19. <tr>
  20. <th>Documento</th>
  21. <th>Nombre</th>
  22. </tr>
  23. </thead>
  24. <tbody>
  25. <tr>
  26. <td>
  27. <input type="text" name="documento[]">
  28. </td>
  29. <td>
  30. <input type="text" name="nombre[]">
  31. </td>
  32. </tr>
  33. <tr>
  34. <td>
  35. <input type="text" name="documento[]">
  36. </td>
  37. <td>
  38. <input type="text" name="nombre[]">
  39. </td>
  40. </tr>
  41. </tbody>
  42. </table>
  43. <input type="submit" name="guardar" value="Guardar">
  44. <?php
  45. $ingresarDatos = new ControladorDatos();
  46. $ingresarDatos -> ctrIngresarDato();
  47. ?>
  48. </form>
  49. </body>
  50. </html>
  51.  
  52. <?php
  53. class ControladorDatos {
  54. static public function ctrIngresarDato(){
  55. if (isset($POST_["documento"])) {
  56. $tabla = "prueba";
  57. $datos = array("documento"=>$POST_["documento"], "nombre"=>$POST_["nombre"]);
  58.  
  59. $respuesta = ModeloDatos::mdlIngresarDatos($tabla, $datos);
  60.  
  61. if ($respuesta == "ok") {
  62. echo "Se han insertado los datos";
  63. } else {
  64. echo "No se han insertado los datos";
  65. }
  66. }
  67. }
  68. }
  69.  
  70. <?php
  71. class Conexion{
  72. static public function conectar(){
  73. $link = new PDO("mysql:host=localhost;dbname=valor","root","");
  74. }
  75. }
  76.  
  77. class ModeloDatos{
  78. static public function mdlIngresarDatos($tabla, $datos){
  79. $stmt = Conexion::conectar()->prepare("INSERT INTO $tabla(documento, nombre) VALUES (:documento, :nombre)");
  80. $stmt->bindParam(":documento", $datos["documento"], PDO::PARAM_STR);
  81. $stmt->bindParam(":nombre", $datos["nombre"], PDO::PARAM_STR);
  82.  
  83. if ($stmt->execute()) {
  84. return "ok";
  85. } else {
  86. return "error";
  87. }
  88.  
  89. $stmt = null;
  90. }
  91. }
Add Comment
Please, Sign In to add comment