Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource(警告:mysql_num_rows():提供的参数不是有效的 MySQL 结果资源)
问题描述
可能重复:
警告:mysql_fetch_array():提供的参数不是有效的 MySQL 结果 
我在下面的代码中收到以下错误消息(位于查询末尾):
I am getting the following error message on the code below (which is at the end of the query):
警告:mysql_num_rows():已提供参数不是有效的 MySQL 结果../view-ind-order.php 中的资源第 28 行
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in ../view-ind-order.php on line 28
该脚本应该检索订单(从列出订单表中所有 order_id 行的页面)、订单内容、订购用户和产品信息.我认为我得到错误的地方是订单中有不止一种产品,但我不太清楚我哪里出错了.(头部有会话启动命令)
This script is supposed to retrieve the order (from a page which lists all of the order_id rows from the orders table), the contents of the order, the user who ordered and the product information. I think where I'm getting the error is where there is more than one product within the order but I can't quite see where I'm going wrong. (the header has a session start command)
     <?php 
      $page_title = "T3JkZXI=";
      include ('./includes/header.html');
      if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) )
      {    
       $id = $_GET['id'];
       } elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) )
       {    
       $id = $_POST['id'];
       } else { 
       echo 'This page has been accessed in error';
       include ('./includes/header.html'); 
       exit();
      }
 require_once ('mydatabase.php'); 
 $query = "SELECT us.users_id, us.users_first_name, us.users_surname, us.users_business, 
             ord.order_id, ord.users_id, ord.total, ord.order_date,  
             oc.oc_id, oc.order_id, oc.products_id, oc.quantity, oc.price
             prd.products_id, prd.products_name, prd.price      
         FROM users AS us, orders AS ord, order_contents AS oc, products AS prd  
         WHERE ord.order_id=$id
         AND us.users_id = ord.users_id
         AND ord.order_id = oc.order_id
         AND oc.products_id = prd.products_id    
         ";
 $result = @mysql_query ($query); 
 if (mysql_num_rows($result) == 1) { 
    $row = mysql_fetch_array ($result, MYSQL_NUM);
    echo '
    <table>
    <tr>
    <td><strong>Name:</strong></td>
    <td>' . $row[1] . ' ' . $row[2] . '</td>
    </tr>
    <tr>
    <td><strong>Business Name</strong></td>
    <td>' . $row[4] . '</td>
    </tr>   
    <tr>
    <td><strong>Total:</strong></td>
    <td>' . $row[7] . '</td>
    </tr>
    <tr>
    <td><strong>Quantity</strong></td>
    <td>' . $row[12] . '</td>
    </tr>
    <tr>
    <td><strong>Product:</strong></td>
    <td>' . $row[15] . '</td>
    </tr>   
    <tr>
    <td><strong>Price:</strong></td>
    <td>' . $row[13] . '</td>
    </tr>
    </table>
    ';
} else { 
    echo '<h1 id="mainhead">Page Error</h1>
    <p class="error">This page has been accessed in error.</p><p><br /><br /></p>';   
}
mysql_close();
include ('./includes/footer.html');
?>
推荐答案
更改 $result = @mysql_query ($query); 
与
$result = mysql_query ($query) or die(mysql_error());
看看你是否有任何错误.
and see if you have any errors.
您在 oc.price 之后和 prd.products_id 之前错过了一个逗号.像这样更改您的查询:
You missed a comma after oc.price and before prd.products_id. Change your query like this:
$query = "SELECT us.users_id, us.users_first_name, us.users_surname, us.users_business, 
             ord.order_id, ord.users_id, ord.total, ord.order_date,  
             oc.oc_id, oc.order_id, oc.products_id, oc.quantity, oc.price/*here*/,/**/
             prd.products_id, prd.products_name, prd.price      
         FROM users AS us, orders AS ord, order_contents AS oc, products AS prd  
         WHERE ord.order_id=$id
         AND us.users_id = ord.users_id
         AND ord.order_id = oc.order_id
         AND oc.products_id = prd.products_id    
         ";
                        这篇关于警告:mysql_num_rows():提供的参数不是有效的 MySQL 结果资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:警告:mysql_num_rows():提供的参数不是有效的 MySQL 结果资源
				
        
 
            
        - Laravel 仓库 2022-01-01
 - 如何定位 php.ini 文件 (xampp) 2022-01-01
 - 带有通配符的 Laravel 验证器 2021-01-01
 - PHP Count 布尔数组中真值的数量 2021-01-01
 - 没有作曲家的 PSR4 自动加载 2022-01-01
 - 正确分离 PHP 中的逻辑/样式 2021-01-01
 - 从 PHP 中的输入表单获取日期 2022-01-01
 - Mod使用GET变量将子域重写为PHP 2021-01-01
 - Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
 - SoapClient 设置自定义 HTTP Header 2021-01-01
 
				
				
				
				