Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE `valor`.`prueba` ( `documento` INT(15) NOT NULL , `nombre` VARCHAR(50) NOT NULL ) ENGINE = InnoDB;
- <?php
- require_once "controlador.php";
- require_once "modelo.php";
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- </head>
- <body>
- <form role="form" method="post">
- <table>
- <thead>
- <tr>
- <th>Documento</th>
- <th>Nombre</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>
- <input type="text" name="documento[]">
- </td>
- <td>
- <input type="text" name="nombre[]">
- </td>
- </tr>
- <tr>
- <td>
- <input type="text" name="documento[]">
- </td>
- <td>
- <input type="text" name="nombre[]">
- </td>
- </tr>
- </tbody>
- </table>
- <input type="submit" name="guardar" value="Guardar">
- <?php
- $ingresarDatos = new ControladorDatos();
- $ingresarDatos -> ctrIngresarDato();
- ?>
- </form>
- </body>
- </html>
- <?php
- class ControladorDatos {
- static public function ctrIngresarDato(){
- if (isset($POST_["documento"])) {
- $tabla = "prueba";
- $datos = array("documento"=>$POST_["documento"], "nombre"=>$POST_["nombre"]);
- $respuesta = ModeloDatos::mdlIngresarDatos($tabla, $datos);
- if ($respuesta == "ok") {
- echo "Se han insertado los datos";
- } else {
- echo "No se han insertado los datos";
- }
- }
- }
- }
- <?php
- class Conexion{
- static public function conectar(){
- $link = new PDO("mysql:host=localhost;dbname=valor","root","");
- }
- }
- class ModeloDatos{
- static public function mdlIngresarDatos($tabla, $datos){
- $stmt = Conexion::conectar()->prepare("INSERT INTO $tabla(documento, nombre) VALUES (:documento, :nombre)");
- $stmt->bindParam(":documento", $datos["documento"], PDO::PARAM_STR);
- $stmt->bindParam(":nombre", $datos["nombre"], PDO::PARAM_STR);
- if ($stmt->execute()) {
- return "ok";
- } else {
- return "error";
- }
- $stmt = null;
- }
- }
Add Comment
Please, Sign In to add comment