0

**

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>";

    }
  • 1) That happened because your query failed. 2) You're mixing the _deprecated_ `mysql` functions with the behavior of `mysqli` 3) `$query = mysql_query("select * from add", $connection);` Sayy Whaat. 4) Did you even google it? – DirtyBit Oct 03 '15 at 07:50

1 Answers1

0

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>";
    }
oreopot
  • 3,274
  • 2
  • 19
  • 26