警告:mysql_fetch_array()期望参数1是资源,[重复]

**

This question already has an answer here:

mysql_fetch_array() expects parameter 1 to be resource (or mysqli_result), boolean given 31 answers

Hi im trying to write the data from my database and this the code thats meant to be doing it but i get two of the 'Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given' and dont know why???? **

     <?php
    $connection = mysql_connect("localhost", "root", ""); 
// Establishing Connection with Server
    $db = mysql_select_db("burger machine", $connection);
 // Selecting Database

    //MySQL Query to read data

    $query = mysql_query("select * from add", $connection);



    while ($row = mysql_fetch_array($query)) {

    echo "<tr>";
    echo " <td> {$row['Addons_id']} </td>";
    echo " <td> <a href=\"Ao.php?update={$row['Addons_id']}\"> {$row['Addons_Name']} </a> </td> ";
    echo " <td> {$row['Addons_Price']} </td> ";
    echo " <td> {$row['Addons_Description']} </td>";
    echo "</tr>";

    }
</div>

use mysqli as mysql is now deprecated and also prone to sql injections.

use mysqli_query($con , $query);

where $query is your SQL query to fetch data and $con is your connection resource variable.

On a side note

In mysql_query(); just pass your query as parameter, not your connection.

<?php
    $connection = mysqli_connect("localhost", "root", ""); 
// Establishing Connection with Server
    $db = mysqli_select_db( $connection , "burger machine" );
 // Selecting Database

    //MySQL Query to read data

    $query = mysqli_query( $connection , "select * from add" );



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

    echo "<tr>";
    echo " <td> {$row['Addons_id']} </td>";
    echo " <td> <a href=\"Ao.php?update={$row['Addons_id']}\"> {$row['Addons_Name']} </a> </td> ";
    echo " <td> {$row['Addons_Price']} </td> ";
    echo " <td> {$row['Addons_Description']} </td>";
    echo "</tr>";
    }