0

Estoy creando un modal que al cambiar el option del select me cambie los valores de la consulta, pero me sale el siguiente error. Alguien me puede explicar que estoy haciendo mal por favor.

Ajax

$("#puestoHorario").change(function(){
        var puestoHorario = $(this).val();
        var turnoHorario = $("#turnoHorario").val();
        
        $.ajax({
            url: 'modal/modalHorarios.php',
            data: {puestoHorario: puestoHorario, turnoHorario: turnoHorario},
            method: 'post',
            success: function(response) {
                $("#tablaHorariosPuesto").html(response);
            }
            
        })
        
    })

PHP

<table id="tablaHorariosPuesto" class="table table-hover table-bordered">
                    <thead>
                        <tr>
                            <th scope="row">Nombre</th>
                            <th>Lunes</th>
                            <th>Martes</th>
                            <th>Miercoles</th>
                            <th>Jueves</th>
                            <th>Viernes</th>
                            <th>Sabado</th>
                            <th>Domingo</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        if(isset($_POST['turnoHorario']) || isset($_POST['puestoHorario'])){
                            $turnoHor = $_POST['turnoHorario'];
                            $puesHora = $_POST['puestoHorario'];
                            $sqlHorTur = "SELECT * FROM personal WHERE puesto='$puesHora' AND turno='$turnoHor'";
                            $queryTurHor = mysqli_query($mysqli, $sqlHorTur);
                            while($turHor = mysqli_fetch_array($queryTurHor)){
                                $datosTurHor .= '<tr>
                                <td>'.$turHor[1].'</td>
                                    </tr>';
                            }
                            echo $datosTurHor;
                        } 
                        ?>
                    </tbody>
                </table>

Y este es el error *** Warning: mysqli_query() expects parameter 1 to be mysqli, null given in

3
  • Si correcto, era eso. Gracias el 5 nov. 2020 a las 3:56
  • Deberías publicar como lo solucionaste
    – BetaM
    el 5 nov. 2020 a las 3:57
  • Solamente agregue el archivo php de la conexion a la BD. include '../../../conexion/conexion.php'; En la conexion esta $mysqli = new MySQLi("localhost", "root", "", "*****l"); Por ese motivo no encontraba los parametros de $mysqli el 5 nov. 2020 a las 12:17

1 respuesta 1

0

Esta muy claro, $mysqli es null, no lo estas definiendo previamente. Creo que la función mysqli_query() espera recibir como primer parámetro la sentencia SQL: https://www.php.net/manual/es/mysqli.query.php

Tu línea:

$queryTurHor = mysqli_query($mysqli, $sqlHorTur);

sería:

$queryTurHor = mysqli_query($sqlHorTur);

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.