mysqli_query () expects parameter 1 to be mysqli, null given in

0

This is my code

<?php 
    if(!isset($_SESSION)) 
  {     
  require_once "/Paises/php/conexion.php";
  $conexion=conexion();
  session_start(); 
  } 



 ?>
<div class="row">
    <div class="col-sm-12">
    <h2>Tabla Registro Ciudad/Pais</h2>
        <table class="table table-hover table-condensed table-bordered">
        <caption>
            <button class="btn btn-primary" data-toggle="modal" data-target="#modalNuevo">
                Agregar nuevo 
                <span class="glyphicon glyphicon-plus"></span>
            </button>
        </caption>
            <tr>
                <td>Nombre</td>
                <td>Apellido</td>
                <td>Email</td>
                <td>Telefono</td>
                <td>Editar</td>
                <td>Eliminar</td>
            </tr>

            <?php 

                if(isset($_SESSION['consulta'])){
                    if($_SESSION['consulta'] > 0){
                        $idp=$_SESSION['consulta'];
                        $sql="SELECT id,nombre,apellido,email,telefono 
                        from gestionelo where id='$idp'";
                    }else{
                        $sql="SELECT id,nombre,apellido,email,telefono 
                        from gestionelo ";
                    }
                }else{
                    $sql="SELECT id,nombre,apellido,email,telefono 
                        from gestionelo";
        }

        $resultado = mysqli_query($conexion,$sql);
        while($row=mysqli_fetch_array($result)){ 

                    $datos=$row[0]."||".
                           $row[1]."||".
                           $row[2]."||".
                           $row[3]."||".
               $row[4];

             ?>

            <tr>
                <td><?php echo $ver[1] ?></td>
                <td><?php echo $ver[2] ?></td>
                <td><?php echo $ver[3] ?></td>
                <td><?php echo $ver[4] ?></td>
                <td>
                    <button class="btn btn-warning glyphicon glyphicon-pencil" data-toggle="modal" data-target="#modalEdicion" onclick="agregaform('<?php echo $datos ?>')">

                    </button>
                </td>
                <td>
                    <button class="btn btn-danger glyphicon glyphicon-remove" 
                    onclick="preguntarSiNo('<?php echo $ver[0] ?>')">

                    </button>
                </td>
            </tr>
            <?php 
        }
             ?>
        </table>
    </div>
</div>
    
asked by Kristian Espitia 08.10.2018 в 22:52
source

2 answers

0

I think it's because you have the $ sql inside the else while $ result = mysqli_query ($ connection, $ sql); outside.

Try:

else{
         $sql="SELECT id,nombre,apellido,email,telefono from gestionelo";
         $resultado = mysqli_query($conexion,$sql);
     }
    
answered by 09.10.2018 в 05:38
0

Pass the code through all the validation processes required. This way you will know where the problem lies:

<?php
if(!isset($_SESSION))
{
    require_once "/Paises/php/conexion.php";
    $conexion=conexion();

    if ($conexion){
        session_start();
        if(isset($_SESSION['consulta'])){
            if($_SESSION['consulta'] > 0){
                $idp=$_SESSION['consulta'];
                $sql="SELECT id,nombre,apellido,email,telefono
                        from gestionelo where id='$idp'";
            }else{
                $sql="SELECT id,nombre,apellido,email,telefono
                        from gestionelo ";
            }
        }else{
            $sql="SELECT id,nombre,apellido,email,telefono
                        from gestionelo";
        }

        $resultado = mysqli_query($conexion,$sql);

        if ($resultado){

/*
  *Hay que agregar este bloque, el cual olvidé tomar 
  *de tu código original
*/
    ?>

<div class="row">
    <div class="col-sm-12">
    <h2>Tabla Registro Ciudad/Pais</h2>
        <table class="table table-hover table-condensed table-bordered">
        <caption>
            <button class="btn btn-primary" data-toggle="modal" data-target="#modalNuevo">
                Agregar nuevo 
                <span class="glyphicon glyphicon-plus"></span>
            </button>
        </caption>
            <tr>
                <td>Nombre</td>
                <td>Apellido</td>
                <td>Email</td>
                <td>Telefono</td>
                <td>Editar</td>
                <td>Eliminar</td>
            </tr>

<?php

/*Aquí sigue el código que ya había*/

            while($row=mysqli_fetch_array($result)){

                $datos=$row[0]."||".
                    $row[1]."||".
                    $row[2]."||".
                    $row[3]."||".
                    $row[4];

?>

            <tr>
                <td><?php echo $ver[1] ?></td>
                <td><?php echo $ver[2] ?></td>
                <td><?php echo $ver[3] ?></td>
                <td><?php echo $ver[4] ?></td>
                <td>
                    <button class="btn btn-warning glyphicon glyphicon-pencil" data-toggle="modal" data-target="#modalEdicion" onclick="agregaform('<?php echo $datos ?>')">

                    </button>
                </td>
                <td>
                    <button class="btn btn-danger glyphicon glyphicon-remove"
                    onclick="preguntarSiNo('<?php echo $ver[0] ?>')">

                    </button>
                </td>
            </tr>
            <?php
            }
?>
        </table>
    </div>
</div>
            <?php

        }else{
            echo "Error en la consulta: ".mysqli_error($conexion);
        }

    }else{

        echo "Error de conexión: ".mysqli_connect_error();
    }

}else{

    echo "Error de sesión";
}
    
answered by 09.10.2018 в 00:53