2013-08-10 1 views
-4

내 페이팔 기부 웹 페이지에서이 오류가 발생하며이를 중지하는 방법을 잘 모릅니다.경고 : mysql_num_rows() : 제공된 인수가 유효한 MySQL 결과 리소스가 아닙니다. - 페이팔 기부 스크립트

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 데이터베이스를 설정했는지 알 수 없습니다. 여기

질문 나는이 웹 사이트 http://tutorialzine.com/2010/05/donation-center-php-mysql-paypal-api/에서 코딩을 사용하고

<?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> 

을의 코드이며, 자신의 데모는 잘 작동하지만 난 내 사용하고 그들이 가지고있는 방법을 설정할 때 자신이 여전히 오류를 던지고 .

+0

$ comments의 값은 무엇입니까? – Blacksonic

+0

아무것도하기 전에 ** silence 연산자 ('@')의 ** 모든 ** 인스턴스를 제거하십시오. 어떤 일이 일어나고 있는지 알려주는 오류를 단순히 억제하면 도움을 줄 수 없습니다. –

+3

더 이상 사용되지 않는 mysql_ * 그것의 사용되지 않는 PDO 또는 mysqli 대신 –

답변

-2

이 줄은 오류 렌더링 : 모든

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

먼저, phpMyAdmin을에

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

를 입력합니다. 이것도 오류를 렌더링합니까?

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 코드를 검색하려고하지 않습니다.

+0

이 스크립트를 사용하여 ',' 를 'NOT NULL 기본 utf8_unicode_ci을 대조), 'donor_email'의 VARCHAR (255'수 있으며 dc_donations'은 ( 은'transaction_id' VARCHAR은 (64) utf8_unicode_ci에게 NOT NULL 기본을 '대조'테이블 만들기 금액 필드를 을 가지고 amount' NOT NULL 기본을 두 배로 '0', 는'original_request' 텍스트가 NULL NOT, 'dt' 타임 스탬프 NOT NULL 기본 CURRENT_TIMESTAMP, PRIMARY KEY ('transaction_id') ) ENGINE =의 MyISAM DEFAULT CHARSET = UTF8 부씩 = utf8_unicode_ci을 utf8_unicode_ci을 대조 ; – user2671297

+1

@ user2671297 질문에이 DDL 코드를 추가하십시오. – SteAp

+0

요다 비교? 이것은 PHP입니다. 함수를 0으로 설정할 수 없기 때문에 mysql_error() = 0'은 에러가됩니다. –

관련 문제