Warning: mysql_query () expects parameter 1 to be string, object given in

1

I need to show the data entered by a user in a modal, which has a data select and enter an amount, these data must be shown in a table after being saved in DB

When saving them, the error I get is:

  

Warning: mysql_query () expects parameter 1 to be string, object given in ....

 <table class="table table-bordered">
                        <thead>
                           <tr> <th>Código</th>
<th>Descripción del Gasto</th>
<th width="150" height="45"> Monto  Generado</th>
<th width="150" height="45">Pago por Apartamento</th>  <th width="120" height="45">Opciones</th>
</tr>
</thead>

<?php
                            $sql = "SELECT * FROM gasto_g";
                            $consulta = mysql_query($conexion,$sql);
                             if($consulta>0){
                            while($resultado = mysql_fetch_array($consulta)){
                            ?> 


<tr>

 <td><?php echo $resultado['id_gasto_g']; ?></td> 


<td><?php echo $resultado['descripcion']; ?> </td> 


<td width="7" height="7"><?php echo $resultado['monto']; ?>  </td> 

<td>  </td>  
<td>   <!--Boton agregar -->

    <div class="col-md-1 col-md-offset-0">
         <button class="btn btn-primary btn-sm" id="sesion" data-toggle="modal" data-target="#registro"  rel="tooltip-left" title="Editar">
                                        <i class="fa fa-pencil"></i>

                                        </button>
    </div>
</div><br>
<!--Boton agregar -->  </td>


</tr>

 <?php
                                }
                            ?>
                        </tbody>
                        <?php
                                }
                            ?>
                    </table>


               </div>
           </div>
    </div><!--/content-body -->
</div><!--/content -->
    
asked by Anderson Rey 09.08.2017 в 20:47
source

2 answers

3

The error is because the mysql_query function is happening to you as the first parameter $conexion and then $sql , when the correct thing is to do it the other way around.

Example:

mysql_query($sql, $conexion);

-

PD : The MySQL extension was declared obsolete in PHP 5.5.0 and deleted in PHP 7.0.0 . Instead the extensions should be used MySQLi or PDO_MySQL .

    
answered by 09.08.2017 / 21:05
source
0

Depending on the version of mysql functions are handled

in this case you must change msql_query (); to msqli_query ()

Since php 5.5.0 and msql_query () was declared obsolete

msqli_query () allows 2 parameters to be received

$ connection._ is the variable that stores the connection of your database

$ query="INSERT QUERY"

msqli_query ($ connection, $ query);

I hope you made me understand

    
answered by 02.03.2018 в 01:34