我已经梳理了这段代码,但终生无法找到错误。这是一个 PHP 文件,我将作为 cron 作业运行以检查已结束的拍卖,并在拍卖结束时向拍卖所有者发送电子邮件。该代码正在向拍卖列表发送电子邮件,但它仅循环通过 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 次拍卖以及为什么我会收到错误消息。 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'];