Hi, I'm changing some php script to OOP aproach, when I try to execute the new class i don't get any result, no error message but also the record is not saved and the redirect function doesn't work, so my question is:
what am I missing in my code? I have the constructor, and from it I call the other 2 function, here is my code, please take a look, regards
<?php
class addemp{
//constructor de la clase
function addemp(){
session_start();
if (@$_SESSION['auth'] !="yes"){
header("Location: nologin.php");
exit();
}
else{
if($_POST['btnenviar']=="Cancelar"){
header('Location: pnomina.php');
}
else{
include("vars.php");
$xnombres=$_POST['txtnombres'];
$xapellidos=$_POST['txtapellidos'];
$xtelefono=$_POST['txttelefono'];
$xdireccion=$_POST['txtdireccion'];
$xciudad=$_POST['txtciudad'];
$xdepto=$_POST['txtdepto'];
$xdui=$_POST['txtdui'];
$xnit=$_POST['txtnit'];
$xnup=$_POST['txtnup'];
$xisss=$_POST['txtisss'];
$xprofesion=$_POST['txtprofesion'];
$xfoto=$_POST['txtfoto'];
$this->agregar;
$this->desplegar;
}
}
}
//fin del constructor
//funcion agregar: graba los datos en la tabla
function agregar(){
$conn=mysqli_connect($host, $user, $password) or die("No se pudo establecer comunicacion");
$db=mysqli_select_db($conn, $basedatos) or die("Error en la base de datos");
$sql="INSERT INTO $tabla1 (apellidos, nombres, profesion, direccion, depto, ciudad, telefono, nit, nup, isss, dui, foto) VALUES ('$xapellidos', '$xnombres', '$xprofesion', '$xdireccion', '$xdepto', '$xciudad', '$xtelefono', '$xnit', '$xnup', '$xisss', '$xdui', '$xfoto')";
mysqli_query($conn, $sql) or die(mysqli_error($conn));
$_SESSION['curnom']=$xnombres;
$_SESSION['curape']=$xapellidos;
$sql="SELECT id FROM $tabla1 WHERE apellidos='$xapellidos' AND nombres='$xnombres'";
$resultado=mysqli_query($conn, $sql) or die(mysqli_error($conn));
$filas=mysqli_num_rows($resultado);
if($filas == 1){
$xid=mysqli_fetch_assoc($resultado);
$_SESSION[ 'curid' ]=$xid['id'];
}
}
function desplegar(){
switch($_POST['btnenviar']){
case "Almacenar":
header('Location: pnomina.php');
break;
case "Contratacion":
header('Location: plaemp.php');
break;
}
}
//fin de funcion agregar()
}//fin de la clase
?>