【问题标题】:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource - paypal donation script警告:mysql_num_rows():提供的参数不是有效的 MySQL 结果资源 - 贝宝捐赠脚本
【发布时间】:2013-08-10 21:56:43
【问题描述】:

我在我的贝宝捐赠网页中收到此错误,我不知道如何阻止它。

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/sixthr6/public_html/donation/donate.php on line 116

我现在正在运行这是演示模式,直到我找到解决此问题的方法。我有一个带有正确表的自定义 mySQL 数据库设置,所以我不知道为什么当我在 DEMO 模式下进行虚假捐赠时,它不会将评论保存到主页而只是抛出该错误。

这是有问题的代码

    <?php

require "config.php";
require "connect.php";

// Determining the URL of the page:
$url = 'http://'.$_SERVER['SERVER_NAME'].dirname($_SERVER["REQUEST_URI"]);

// Fetching the number and the sum of the donations:
list($number,$sum) = mysql_fetch_array(mysql_query("SELECT COUNT(*),SUM(amount) FROM dc_donations"));

// Calculating how many percent of the goal were met:
$percent = round(min(100*($sum/$goal),100));

// Building a URL with Google's Chart API:
$chartURL = 'http://chart.apis.google.com/chart?chf=bg,s,f9faf7&amp;cht=p&amp;chd=t:'.$percent.',-'.(100-$percent).'&amp;chs=200x200&amp;chco=639600&amp;chp=1.57';

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Donation Center | Tutorialzine demo</title>

<link rel="stylesheet" type="text/css" href="styles.css" />

</head>

<body>

<div id="main">
    <h1>Donation Center</h1>
    <h2>Show Your Support for our Cause</h2>

    <div class="lightSection">
        <h3>Hello, dear visitor!</h3>
        <p>This is Tutorialzine's Donation Center. It utilizes PayPal's APIs to bring you a fully fledged donation solution. It is currently in <strong>Demo Mode</strong>, which means that PayPal is bypassed and you can donate as much as you want to test the functionality. You can, however, just change a variable in the config.php file to enable real donations.</p>    

        <!-- The PayPal Donation Button -->

      <form action="<?php echo $payPalURL?>" method="post" class="payPalForm">
        <div>
            <input type="hidden" name="cmd" value="_donations" />
            <input type="hidden" name="item_name" value="Donation" />

            <!-- Your PayPal email: -->
            <input type="hidden" name="business" value="<?php echo $myPayPalEmail?>" />

            <!-- PayPal will send an IPN notification to this URL: -->
            <input type="hidden" name="notify_url" value="<?php echo $url.'/ipn.php'?>" /> 

            <!-- The return page to which the user is navigated after the donations is complete: -->
            <input type="hidden" name="return" value="<?php echo $url.'/thankyou.php'?>" /> 

            <!-- Signifies that the transaction data will be passed to the return page by POST -->
            <input type="hidden" name="rm" value="2" /> 


            <!--    General configuration variables for the paypal landing page. Consult 
                    http://www.paypal.com/IntegrationCenter/ic_std-variable-ref-donate.html for more info  -->

            <input type="hidden" name="no_note" value="1" />
            <input type="hidden" name="cbt" value="Go Back To The Site" />
            <input type="hidden" name="no_shipping" value="1" />
            <input type="hidden" name="lc" value="US" />
            <input type="hidden" name="currency_code" value="USD" />


            <!-- The amount of the transaction: -->

            <select name="amount">
                <option value="50">$50</option>
                <option value="20">$20</option>
                <option value="10" selected="selected">$10</option>
                <option value="5">$5</option>
                <option value="2">$2</option>
                <option value="1">$1</option>
            </select>

            <input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHostedGuest" />

            <!-- You can change the image of the button: -->
            <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donate_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!" />

          <img alt="" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1" />
        </div>
        </form>

    </div>

    <!-- Setting the Google Chart API address as the background image of the div: -->

    <div class="chart" style="background:url('<?php echo $chartURL?>');">
        Our Goal
    </div>

    <div class="donations">
        <?php echo $percent?>% done
    </div>


    <div class="clear"></div>

    <div class="donors">
        <h3>The Donor List</h3>
        <h4>Folks Who Showed Their Support</h4>

        <div class="comments">

        <?php
            $comments = mysql_query("SELECT * FROM dc_comments ORDER BY id DESC");

            // Building the Donor List:

            if(mysql_num_rows($comments)) 
            {
                while($row = mysql_fetch_assoc($comments))
                {
                    ?>

                        <div class="entry">
                            <p class="comment">
                            <?php 
                                echo nl2br($row['message']); // Converting the newlines of the comment to <br /> tags
                            ?>
                            <span class="tip"></span>
                            </p>

                            <div class="name">
                                <?php echo $row['name']?> <a class="url" href="<?php echo $row['url']?>"><?php echo $row['url']?></a>
                            </div>
                        </div>

                    <?php
                }
            }
        ?>


        </div> <!-- Closing the comments div -->

    </div> <!-- Closing the donors div -->

</div> <!-- Closing the main div -->


</body>
</html>

我正在使用来自该网站http://tutorialzine.com/2010/05/donation-center-php-mysql-paypal-api/ 的编码,他们的演示工作正常,但是当我使用我的并设置它时,他们仍然会抛出错误。

【问题讨论】:

  • $cmets 的值是多少?
  • 在执行任何操作之前,请删除静音运算符 (@) 的 所有 个实例。如果您只是压制告诉您正在发生的事情的错误,我们无法为您提供帮助。
  • 不要使用 mysql_* 它不推荐使用 PDO 或 mysqli 代替
  • 你的查询,那 num 行正在使用,失败,调试一下
  • 我删除了所有 @ 现在我收到此错误警告:mysql_fetch_array():提供的参数不是第 10 行 /home/sixthr6/public_html/donation/donate.php 中的有效 MySQL 结果资源

标签: php


【解决方案1】:

此行呈现错误:

list($number,$sum) = mysql_fetch_array(mysql_query("SELECT COUNT(*),SUM(amount) FROM dc_donations"));

首先,输入

SELECT COUNT(*),SUM(amount) FROM dc_donations

在 phpMyAdmin 中。这也会导致错误吗?

dc_donations 是否存在,是否有 amount 字段?

请检查错误

检查错误的一种方法是这样的:

$donationQuery = "SELECT COUNT(*),SUM(amount) FROM dc_donations";

$cursor = mysql_query( $donationQuery );
assert( ! mysql_errno() );
assert( is_resource( $cursor ));

list($number,$sum) = mysql_fetch_array( $cursor );

看到assert() 函数调用了吗?此函数评估其参数。如果它不评估为 TRUE,它会打印一条错误消息。 assert() docs.

提示您的下一个问题

您的代码示例包含大量无关信息。所有这些 HTML 代码都与您的问题无关。

为了找到根本原因,明智的做法是减少文件中的代码量。同样,您的问题也可能会得到更多答案 - 没有人想在代码示例中搜索相关的 PHP 代码

【讨论】:

  • 我使用这个脚本来设置表格,它确实有一个金额字段 CREATE TABLE dc_donations (transaction_id varchar(64) collat​​e utf8_unicode_ci NOT NULL default '', donor_email varchar(255 ) collat​​e utf8_unicode_ci NOT NULL default '', amount double NOT NULL default '0', original_request text collat​​e utf8_unicode_ci NOT NULL, dt timestamp NOT NULL default CURRENT_TIMESTAMP, PRIMARY KEY (transaction_id) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  • 尤达比较?这是PHP。 mysql_error() = 0 将是一个错误,因为您不能将函数设置为 0。
  • 可能是因为您回答了一个错误的问题?
  • 您使用 Yoda 比较 (0 == mysql_error())。原因是防止输入mysql_error() == 0 的人输入mysql_error() = 0
  • 是的。每一个 modern 编译器都会警告你它们。没有必要。
猜你喜欢
  • 2011-09-22
  • 2013-01-27
  • 1970-01-01
  • 2011-04-11
  • 2011-04-24
  • 2023-03-31
  • 1970-01-01
  • 1970-01-01
  • 2013-05-08
相关资源
最近更新 更多