I am trying to make my first database insert autonomously, I have inserted in the same way but guided by videos previously on the same page from a user registry.
I have the problem in ValidadorEconomia because it returns an empty array and I don't know why, here is an example of what the two $dni and $validator arrays return:
AddEconomy Here I have the code of the main page:
if (isset($_POST["economia"])){
Conexion::abrir_conexion();
$dni = RepositorioUsuario::obtener_dni(Conexion::obtener_conexion(), $_SESSION['nombre_usuario']);
$validador = new ValidadorEconomia($_POST["ingreso"], $_POST["gasto"], $_POST["nota"], Conexion :: obtener_conexion());
echo json_encode($dni);
echo json_encode($validador);
if ($validador -> economia_valida()){
//Aquí tiene que entrar
}
Conexion::cerrar_conexion();
}
<div class="card-body">
<form role="form" method="post"
action="<?php echo $_SERVER['PHP_SELF'] ?>">
<?php
if(!isset($_POST["economia"])){
include_once "economia_vacio.inc.php";
}
?>
</form>
</div>
economy_action:
echo $_POST["ingreso"];
echo "<br>";
echo $_POST["gasto"];
echo "<br>";
echo $_POST["nota"];
echo "<br>";
ValidatorEconomy:
class ValidadorEconomia {
private $ingreso;
private $gasto;
private $nota;
public function __construct($ingreso, $gasto, $nota, $conexion)
{
$this -> ingreso = "";
$this -> gasto = "";
$this -> nota = "";
}
public function economia_valida(){
if($this -> ingreso === "" ||
$this -> gasto === ""){
return false;
}else{
return true;
}
}
The error was in this function, it was not adding any value.
The correct code would be like this:
And to display the string we will use: