Save data from a PHP form

0

Nesesito receive data from a form by POST method, I have a Controller in the Controller Folder.

Code Controller / Controller

  <?php
require '../Modelo/Controlador.php';
//Llegan datos de formulario por metodo POST y se guardan
  $habitantes =new Controlador();
  $habitantes->agregarHabitante($_POST['identificacion'],$_POST['nombres'], $_POST['apellidos'], $_POST['apto'], $_POST['interior'],   $_POST['telefono'],$_POST['correo']);



   $egresos = new Controlador();
   $egresos->crearComprobante($_POST['Codigo'], $_POST['Concepto'],  $_POST['Valor'],$_POST['Observaciones'],$_POST['PagadoA'] ,$_POST['Cheque'] ,$_POST['Efectivo'] , $_POST['Banco'], $_POST['ElaboradoPor'], $_POST['identificacion']);

The problem is that in order for the data of a form to be inserted into the database, I must comment on one of the 2 codes.

Model driver code Model / Controller

<?php
require 'GestorEgresos.php';
require 'GestorHabitantes.php';
require 'Conexion.php';
require 'Egresos.php';
require 'Habitantes.php';

class Controlador{

public function crearComprobante($codigo, $concepto, $valor, $observaciones, $pagadoA, $cheque, $efectivo, $banco, $elaboradoPor, $identificacion){
    $Egresos = new Egresos($codigo, $concepto, $valor, $observaciones, $pagadoA, $cheque, $efectivo, $banco, $elaboradoPor, $identificacion);
    $GestorEgresos=new GestorEgresos();
    $registro = $GestorEgresos->crearComprobante($Egresos);
    if($registro >0){
        echo "Comprobante de Egresos creado Correctamente...";
    }else{
        echo "Error al crear el Comprobante...";
    }
}

public function agregarHabitante($identificacion, $nombres, $apellidos, $apto, $interior, $telefono, $correo){
    $Habitantes = new Habitantes($identificacion, $nombres, $apellidos, $apto,  $interior, $telefono, $correo);
    $GestorHabitantes = new GestorHabitantes();
    $registros = $GestorHabitantes->agregarHabitantes($Habitantes);
    if($registros >0){
        echo "Habitante Agregado Correctamente...";
    }else{
        echo "Error! El Habitante ya existe...";
    }
}

I do not know if you made me understand.

    
asked by Santiago Rodriguez 06.04.2018 в 03:02
source

1 answer

0

Well I found the solution in the following way. The problem was that data was being sent from the first form the controller found. To fix it I did it with isset, I leave the code.

<?php

require '../Modelo/Controlador.php';
//Llegan datos de formulario por metodo POST y se guardan

$controlador = new Controlador();
if(isset($_GET["accion"])){
if($_GET["accion"]=="crearComprobante"){
    $controlador->crearComprobante( $_POST['Concepto'],  $_POST['Valor'],$_POST['Observaciones'],$_POST['PagadoA'] ,$_POST['Cheque'] ,$_POST['Efectivo'] , $_POST['Banco'], $_POST['ElaboradoPor'], $_POST['identificacion']);
}elseif($_GET["accion"]== "crear"){
    $controlador->agregarHabitante($_POST['identificacion'], $_POST['nombres'], $_POST['apellidos'], $_POST['apto'], $_POST['interior'], $_POST['telefono'],$_POST['correo']);
}

}
?>
    
answered by 06.04.2018 в 16:25