dongzanghua8422 2015-10-03 07:49
浏览 44

警告: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>
  • 写回答

1条回答 默认 最新

  • duanlangwen9597 2015-10-03 07:54
    关注

    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>";
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?