我已经梳理了这段代码而且不能为我的生活找到错误。这是一个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'];
答案 0 :(得分:0)
现在的错误是什么?它现在在哪一行?身份listing_id
和user_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!