2013-04-28 68 views
-2

我已經梳理了這段代碼,並且不能爲我的生活找到錯誤。這是一個PHP文件,我將作爲cron作業運行以檢查結束的拍賣,並且在拍賣結束時發送一封電子郵件給拍賣所有者,代碼發送一封電子郵件給拍賣名單,但它只是通過1次拍賣循環,我假設這是因爲它在代碼中發現錯誤並且正在死亡但我無法找出錯誤。SQL error - near「at line 1

這裏是代碼的全部...

// Include the configuration file 
require_once 'includes/config.php'; 

$currenttime = strtotime('now'); 

//Query the dateabase for listings which have ended in the past 5 minutes. 
$endauctionquery = "SELECT * FROM listings WHERE end_date < NOW() AND cron_ended=0"; 
     $endauction = mysql_query($endauctionquery) or die('SQL Error :: '.mysql_error()); 

    if(mysql_num_rows($endauction) > 0){ 

     //Loop through the listings and send the appropriate emails 
     while($endauctionrow=mysql_fetch_assoc($endauction)) { 

     //Global variables for the loop 
     $sellerid = $endauctionrow['user_id']; 
     $itemquantity = $endauctionrow['item_quant']; 
     $listingid = $endauctionrow['id']; 
     $sellerquery = "SELECT * FROM settings WHERE user_id=$sellerid"; 
     $sellersql = mysql_query($sellerquery) or die('SQL Error :: '.mysql_error()); 
     $sellerqueryrow = mysql_fetch_assoc($sellersql); 

      //Check to see if the listing is an Auction or Fixed Price 
      if ($endauctionrow['auc_fp'] == "Auction") { 

      //Global variables for Auction listings 
      $bidmaxquery = "SELECT * FROM bids WHERE listing_id=$listingid ORDER BY bid DESC LIMIT 1"; 
      $bidmax = mysql_query($bidmaxquery) or die('SQL Error :: '.mysql_error()); 
      $bidmaxrow = mysql_fetch_assoc($bidmax); 
      $highestbid = $bidmaxrow['bid']; 
      $highestbidderid = $bidmaxrow['user_id']; 

      $highestbidderquery = "SELECT * FROM settings WHERE user_id=$highestbidderid"; 
      $highestbidder = mysql_query($highestbidderquery) or die('SQL Error :: '.mysql_error()); 
      $highestbidderrow = mysql_fetch_assoc($highestbidder); 
      $highestbiddername = $highestbidderrow['display_name']; 

       //Check to see if the item quantity is zero (has it been sold yet?) 
       if ($itemquantity < "1") { 

         //Set the message for an Auction that is marked as sold 
         $itemmessage = 'According to our records, your auction has sold. The winning bidder was <a href="http://myauctionpage.com/mypage.php?user='.$highestbidderid.'">'.$highestbiddername.'</a>. Please be sure to contact the winning bidder for payment and to work out deliver/shipping details. If you chose to include a PayPal Buy Now button for your listing, please check your PayPal account for shipping/delivery instructions as My Auction Page does not handle any shipping or payment processing.<br /><br />If for some reason an agreement cannot be reached with the buyer, you may opt to offer the item to the next highest bidder. The bid history can be found on the listing page here <a href="http://myauctionpage.com/item.php?item='.$listingid.'">'.$endauctionrow['title'].'</a><br /><br />Thank You,<br />My Auction Page Administration'; 

       } else { 
        //Check to see if any bids were placed 
        if (mysql_num_rows($bidmax) == "1") { 
        //Set the message for an Auction that has at least one bid but has not yet been marked as sold. 
        $itemmessage = 'According to our records, your item has not yet been paid for. The winning bidder was <a href="http://myauctionpage.com/mypage.php?user='.$highestbidderid.'">'.$highestbiddername.'</a>. Please be sure to contact the winning bidder for payment and to work out deliver/shipping details. If you chose to include a PayPal Buy Now button for your listing, please check your PayPal account for shipping/delivery instructions as My Auction Page does not handle any shipping or payment processing.<br /><br />If for some reason the winning bidder cannot be contacted for payment or an agreement cannot be reached, you may opt to offer the item to the next highest bidder. The bid history can be found on the listing page here <a href="http://myauctionpage.com/item.php?item='.$listingid.'">'.$endauctionrow['title'].'</a><br /><br />Thank You,<br />My Auction Page Administration'; 
        } else { 
        //Set the message for an Auction that has no bids and has been marked as sold. 
        $itemmessage = 'According to our records there were no bids on your item. You may reactivate your listing easily by following the link above and clicking "Edit Listing" to extend the Auction End Date.'; 
         } 
       } 
       //Finish compiling the email variables 
       $email = $sellerqueryrow['email']; 
       $subject = "Your Auction listing has expired at MyAuctionPage.com!"; 
       $message = 'Hello '.$sellerqueryrow['display_name'].',<br /><br />Your listing for <a href="http://myauctionpage.com/item.php?item='.$listingid.'">'.$endauctionrow['title'].'</a> at My Auction Page has expired. '.$itemmessage.'<br /><br />Thank You,<br />My Auction Page Administration'; 

       require_once 'classes/class.generalemail.php'; 
       if ($mailsendreport == "1") { 
        $updatecron = "UPDATE listings SET cron_ended=1 WHERE id=$listingid"; 
        mysql_query($updatecron) or die('SQL Error :: '.mysql_error()); 
        } 

      } else { 

      //Send the email for a Fixed Price listing 
      if ($itemquant < "1") { 
      $itemmessage = 'According to our records, your item has sold. If you chose to include a PayPal Buy Now button for your listing, please check your PayPal account for shipping/delivery instructions as My Auction Page does not handle any shipping or payment processing. If you have more of this item to sell, and since this was a Fixed Price listing, you may edit your listing and extend the date by following the link above and clicking "Edit Listing". You may then update the number of items you have for sale.'; 
      } else { 
      $itemmessage = 'According to our records, your item has not sold. If you would like to relist your item you may edit your listing and extend the date by following the link above and clicking "Edit Listing". If this item has sold, please follow the link above, log in, and click the button "Mark this item as sold" to let others know it is no longer available.'; 
      } 
      $subject = "Your listing has expired at MyAuctionPage.com!"; 
      $message = 'Hello '.$sellerqueryrow['display_name'].',<br /><br />Your listing for <a href="http://myauctionpage.com/item.php?item='.$listingid.'">'.$endauctionrow['title'].'</a> at My Auction Page has expired. '.$itemmessage.'<br /><br />Thank You,<br />My Auction Page Administration'; 

       require_once 'classes/class.generalemail.php'; 
       if ($mailsendreport == "sent") { 
        $updatecron = "UPDATE listings SET cron_ended=1 WHERE id=$listingid"; 
        mysql_query($updatecron) or die('SQL Error :: '.mysql_error()); 
        } 
      } 

     } 

    } else { 
    } 

誰能幫助我弄清楚這是爲什麼只有通過1個成交循環,爲什麼我得到的ER ROR。 SQL Error :: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

在採納了建議並對死亡陳述編號後,我已經縮小了這個問題的範圍。以下是引發錯誤的部分代碼:

//Global variables for Auction listings 
      $bidmaxquery = "SELECT * FROM bids WHERE listing_id=$listingid ORDER BY bid DESC LIMIT 1"; 
      $bidmax = mysql_query($bidmaxquery) or die('SQL Error 3 :: '.mysql_error()); 
      $bidmaxrow = mysql_fetch_assoc($bidmax); 
      $highestbid = $bidmaxrow['bid']; 
      $highestbidderid = $bidmaxrow['user_id']; 

      $highestbidderquery = "SELECT * FROM settings WHERE user_id=$highestbidderid"; 
      $highestbidder = mysql_query($highestbidderquery) or die('SQL Error 4 :: '.mysql_error()); 
      $highestbidderrow = mysql_fetch_assoc($highestbidder); 
      $highestbiddername = $highestbidderrow['display_name']; 
+0

什麼是1號線? – 2013-04-28 14:45:33

+0

@echo_me MySQL行1引用查詢的第一行,通常是整個查詢。 – 2013-04-28 14:46:29

+0

你可以通過給SQL錯誤::'消息編號開始。讓它們成爲'SQL Error(1)',2,3等等。然後你知道哪個是壞的。 – 2013-04-28 14:47:57

回答

0

現在的錯誤是什麼?現在在哪一行?編號爲listing_iduser_id的整數是 ?或字符串?

如果字符串,那麼你應該使用:

$bidmaxquery = "SELECT * FROM bids WHERE listing_id="' .$listingid. '" ORDER BY bid DESC LIMIT 1"; 
      $bidmax = mysql_query($bidmaxquery) or die('SQL Error 3 :: '.mysql_error()); 
      $bidmaxrow = mysql_fetch_assoc($bidmax); 
      $highestbid = $bidmaxrow['bid']; 
      $highestbidderid = $bidmaxrow['user_id']; 

      $highestbidderquery = "SELECT * FROM settings WHERE user_id="' .$highestbidderid. '""; 
      $highestbidder = mysql_query($highestbidderquery) or die('SQL Error 4 :: '.mysql_error()); 
      $highestbidderrow = mysql_fetch_assoc($highestbidder); 
      $highestbiddername = $highestbidderrow['display_name']; 

//Sorry unable to post this as a comment. Reputation does not allow me! 
相關問題