Nota de Error PhpMyAdmin

Iniciado por Sempai15, 13 Febrero 2018, 21:28 PM

0 Miembros y 1 Visitante están viendo este tema.

Sempai15

Hola lo que pasa es que estoy haciendo como deber una conexión entre php (netbeans) y Mysql (XAMPP), ya tengo el diseño de un formulario pero al intentarlo me sale esto:

Fatal error: Call to a member function hayDatos() on null in C:\xampp\htdocs\phpExamenTamayo\vista\empleado_editar.php on line 71

Este es el código de hayDatos()

Código (php) [Seleccionar]
<?php

class Conexion {
    
//put your code here
    
    
private $baseDatos;
    private 
$servidor;
    private 
$usuario;
    private 
$clave;
    private 
$conexionID 0;
    private 
$consultaID 0;

    
/* Numero de error y texto de error */
    
public $Errno 0;
    public 
$Error '';
    private 
$posFilaActual 0;

    function 
__construct() {
        
$this->baseDatos 'examentamayo';
        
$this->servidor 'localhost';
        
$this->usuario 'root';
        
$this->clave '';
        
$this->conectar();
    }

    
/* Conexion a la base de datos */

    
private function conectar() {
        
//Conectamos al servidor
        
$this->conexionID mysql_connect($this->servidor,
                        
$this->usuario$this->clave);
        if (!
$this->conexionID) {
            
$this->Error 'Ha fallado la conexion';
return 0;
        }
        
//Seleccionamos la base de datos
        
if (!mysql_select_db($this->baseDatos,
                        
$this->conexionID)) {
echo 'Imposible abrir la base de datos';
            
$this->Error 'Imposible abrir la base de datos';
            return 
0;
        }
        
/* Si hemos tenido Ã©xito conectando
          devuelve el identificador de la conexión */
        
return $this->conexionID;
    }

    
/* Ejecuta una consulta */
public function iniciarTransaccion()
{
mysql_query("BEGIN");
}
public function terminarTransaccion()
{
mysql_query("COMMIT");
}
   
   public function 
consultar($sql '') {
        
$this->posFilaActual 0;
        if (
$sql == '') {
            
$this->Error 'No ha especificado la consulta SQL';
            return 
0;
        }
        
//Ejecutamos la consulta
mysql_query("SET NAMES utf8");
        
$this->consultaID mysql_query($sql$this->conexionID);
        if (!
$this->consultaID) {
            
$this->Errno 0//mysql_errono();
            
$this->Error 'Hay un error'//mysql_error();
            
return 0;
        }
        
$this->Errno 1;

        return 
$this->consultaID;
    }

    
/* Numero de campos de una consulta */

    
public function numCampos() {
        return 
mysql_num_fields($this->consultaID);
    }

    
/* Numero de registros de una consulta */

    
public function numRegistros() {
        return 
mysql_num_rows($this->consultaID);
    }

    
/* Numero de un campo de una consulta */

    
public function nombreCampo($numCampo) {
        return 
mysql_field_name($this->consultaID$numCampo);
    }

    public function 
obtenerFilaArray() {
        
$row mysql_fetch_row($this->consultaID);
        
$this->posFilaActual $this->posFilaActual 1;
        return 
$row;
    }

    public function 
obtenerFila() {
        
$row mysql_fetch_array($this->consultaID);
        
$this->posFilaActual $this->posFilaActual 1;
        return 
$row;
    }

    public function 
obtenerFilaAssoc() {
        
$row mysql_fetch_array($this->consultaIDMYSQL_ASSOC);
       
$this->posFilaActual $this->posFilaActual 1;
        return 
$row;
    }

    public function 
hayDatos() {
        if (
$this->Errno == 1) {
            if (
$this->posFilaActual $this->numRegistros())
                return 
true;
        }
        return 
false;
    }

}
?>


Y este es el de Control_Empleado
Código (php) [Seleccionar]
<?php
include_once 'modelo/ModeloEmpleado.php';
$emp = new ModeloEmpleado();
$emp1 = new ModeloEmpleado();
$emp2 = new ModeloEmpleado();

/// despachador

if ($_REQUEST['accion'] == "empleado_lista") {
    
$emp->ver_empleado();
    include_once 
'vista/empleado_lista.php';
} else
if (
$_REQUEST['accion'] == "empleado_nueva") {
    
$emp->ver_empleado();
    include_once 
'vista/empleado_nueva.php';
} else
if (
$_REQUEST['accion'] == "EmpleadoGuardar") {
    
$emp1->guardar_empleado($_POST['Cedula_Persona'], $_POST['ID_usuario'], $_POST['Departamento'], $_POST['Inicio_Contrato'], $_POST['Fin_Contrato'], $_POST['Salario'], $_POST['Años_Trabajo'])
    
?>

    <script type="text/javascript">
        alert ('se agrego  exitosamente');
    </script>

    <?php

    $emp
->ver_empleado();
    include_once 
'vista/empleado_lista.php';
} else
if (
$_REQUEST['accion'] == "editar_empleado") {
    
$emp->ver_emp1($_REQUEST['Cedula_Persona']);
    include_once 
'vista/empleado_editar.php';
} else
if (
$_REQUEST['accion'] == "EmpleadoModificar") {

    
$emp1->modificar_empleado($_REQUEST['Cedula_Persona'], $_POST['ID_usuario'], $_POST['Departamento'], $_POST['Inicio_Contrato'], $_POST['Fin_Contrato'], $_POST['Salario'], $_POST['Años_Trabajo'])
    
?>

    <script type="text/javascript">
        alert ('se modifico exitosamente');
    </script>

    <?php
    $emp
->ver_empleado();
    include_once 
'vista/empleado_lista.php';



Alguien ayuda

srWhiteSkull

Mueetra el codigo de empleado_editar.php pero con el contenido exacto para que coincida con la linea de error, 71

Sempai15

Aquí esta el empleado_editar

Código (php) [Seleccionar]
<?php
session_start
();
//if ((isset($_SESSION['usuario']))and $_SESSION['id_perfil']==4)
//{
?>


<html xmlns = "http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" />
        <title>EDITAR USUARIO</title>

        <script languaje = "javascript">

            < script type = "text/javascript" src = "../validaciones/validar.js" ></script>
        <script type="text/javascript" src="../validaciones/validar2.js"></script>
        <script>
            <!--
            /*VALIDACION PARA SOLO NUMEROS*/

            function validarNumero(e) {
                tecla = (document.all) ? e.keyCode : e.which;
                if (tecla == 8 || tecla == 0)
                    return true;
                patron = /[0123456789.]/;
                te = String.fromCharCode(tecla);
                return patron.test(te);
            }
            function validarletras(e) {
                tecla = (document.all) ? e.keyCode : e.which;
                if (tecla == 8 || tecla == 0)
                    return true;
                patron = /[qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM]/;
                te = String.fromCharCode(tecla);
                return patron.test(te);
            }
            //-->
           
           
           
        </script>
    </head>

    <body >
        <?php
//include('../plantilla/cabecera6.php');
        
?>


        <h3 class="art-postheader">EDITAR EMPLEADO</h3>



        <table align="center" width="100%" border="1">
            <tr>
                <td align="center" width="20%"><input type="button" value="ATRAS" name="atras"/></td>
                <td align="center" width="20%"><input type="button" value="NUEVO" name="nuevo"/></td>
                <td align="center" width="20%"><input type="reset" value="LIMPIAR" name="limpiar"/></td>
                <td align="center" width="20%"><input type="button" value="ADELANTE" name="adelante"/></td>
                <td align="center" width="10%">

                    <!--                    <form name="form_reloj">
                                            <input type="text" id="reloj" name="relo" />
                                        </form>-->
                </td>

            </tr>
        </table>

        </head>   
        <?php
        
// put your code here
        
if ($emp1->hayDatos()) {
            
$fila $emp1->obtenerFila();
        }
        
?>

        <form name="form1" method="post" action="Control_Empleado.php?accion=EmpleadoModificar&amp;ID=<?php echo $fila['Cedula_Persona'?>">
            <table width="100%" align="center">
                <tr>
                    <tr>
                        <th height = "29" align = "left" scope = "col"><div align = "right">CEDULA PERSONA:</div></th>
                        <td><label></label>
                            <input name = "Cedula_Persona" type = "text" id = "Cedula_Persona" onkeypress = "return  validarNumero()(event);" onkeyup = "this.value = this.value.toUpperCase();
                                   " value = "" size = "45" readonly = "readonly" required = "required"/></td>
                    </tr>
                    <tr>
                        <th height="29" align="left" scope="col"><div align="right">ID_USUARIO:</div></th>
                        <td><label></label>
                            <input name="ID_Usuario" type="text" id="ID_Usuario" size="50" onkeypress="return  validarletras()(event);" required="required" onkeyup="this.value = this.value.toUpperCase();"/></td>
                    </tr>
                    <tr>
                        <th height="29" align="left" scope="col"><div align="right">DEPARTAMENTO:</div></th>
                        <td><label></label>
                            <input name="Departamento" type="text" id="Departamento" size="50" onkeypress="return  validarletras()(event);" required="required" onkeyup="this.value = this.value.toUpperCase();"/></td>
                    </tr>
                    <tr>
                        <th height="29" align="left" scope="col"><div align="right">INICIO DE CONTRATO:</div></th>
                        <td><label></label>
                            <input name="Inicio_Contrato" type="text" id="Inicio_Contrato" size="50" required="required" onkeyup="this.value = this.value.toUpperCase();"/></td>
                    </tr>
                    <tr>
                        <th height="29" align="left" scope="col"><div align="right">FIN DE CONTRATO:</div></th>
                        <td><label></label>
                            <input name="Fin_Contrato" type="text" id="Fin_Contrato" size="50" required="required" onkeyup="this.value = this.value.toUpperCase();"/></td>
                    </tr>
                    <tr>
                        <th height="29" align="left" scope="col"><div align="right">SALARIO:</div></th>
                        <td><label></label>
                            <input name="Salario" type="Salario" id="Celular" size="50" onkeypress="return  validarNumero()()(event);" required="required" onkeyup="this.value = this.value.toUpperCase();"/></td>
                    </tr>
                    <tr>
                        <th height="29" align="left" scope="col"><div align="right">AÑOS DE TRABAJO:</div></th>
                        <td><label></label>
                            <input name="Año_Trabajo" type="Salario" id="Año_Trabajo" size="50" onkeypress="return  validarNumero()()(event);" required="required" onkeyup="this.value = this.value.toUpperCase();"/></td>
                    </tr>
                    <tr>
                        <td align = "right">&nbsp;
                        </td>
                        <td><label>
                                <input type = "submit" name = "Submit" value = "GUARDAR" />
                            </label></td>
                    </tr>
            </table>
        </form>
        <?php
        
include('../plantilla/pie.php');
        
?>

    </body>

</html>
<?php
/*
  }
  else
  {
  session_destroy();
  header("Location: ../index.php");
  }
 */
?>

srWhiteSkull

Podría ser que $emp1 no estuviera instanciada llegado a esa parte,  así  que antes de ejecutar esa línea mete esa condición en otra condición para que lo verifique usando isset($emp1)  y de no estar instanciado en el bloque del else pones echo "El error se debe a eso" a fin de depurar.

También me he fijado que no hay un session_start() cuando instancias en Control_empleado,  así que antes de ponerlo junto a lo que indiqué antes también en el mismo empleado_editar al comienzo depura con un echo el session_start() que tienes en la cabecera para saber si está creando una nueva sesión o simplemente la está recuperando que sería lo correcto.

http://php.net/manual/es/function.session-start.php