编辑#1:正如您在下面看到的,我有多个$ db->查询,我想知道这个问题是否可能是由于在较慢的连接上对数据库的调用过多而引起的?因为页面本身可以正常运行数据库调用。如果这是问题,那将是一个很好的解决方案吗?
我一直很难用这个。有些原因,数据库代码只能为客户提供2/3的时间。我一直无法找到为什么它对他们不起作用的原因。
当一些客户使用我的视线时,一切正常,直到最后一页,支付网关向我发送交易ID并确认付款是否成功(1表示是0表示否)。但由于某种原因,添加事务的数据库行无法正常工作
$db->query("UPDATE transactions
SET charge_id = '{$trans_id}'
WHERE cart_id = '{$cart_id}'");
$cart_id
来自cookie(问题不在于阻止cookie的用户。)现在我以前认为这个问题在safari和IE中存在(因为有问题的客户有这些浏览器)但经过一些测试后两个浏览器都可以在我的计算机和朋友身上运行(以防万一)。所以现在我真的不知道问题是什么。如果没有设置交易ID,交易将不会被标记为完成,这意味着它不会在管理面板库存系统中注册,并且项目的数量不会更新。有序和物品正在经历和处理所以问题必须在这个页面上。
目前可能的想法(不确定如何解决):
数据库查询太多会导致网络速度较慢的人员出现问题。
自动循环侧栏导致问题(第二代码块)
代码:
<?php require_once 'system/init.php'; include 'includes/head.php'; include 'includes/navigation.php'; include 'includes/headerpartial.php'; include 'includes/leftbar.php'; ?>
<div id="maincontent" class="col-md-8">
<?php
if ($_GET['response_code'] == 1) { $trans_id = $_GET['transaction_id'];
$db->query("UPDATE transactions SET charge_id = '{$trans_id}' WHERE cart_id = '{$cart_id}'");
$db->query("UPDATE cart SET paid = 1 WHERE id = '{$cart_id}'");
$tsql = $db->query("SELECT * FROM transactions WHERE charge_id = '$trans_id' ");
$tran = mysqli_fetch_assoc($tsql);
$domain = '.'.$_SERVER['HTTP_HOST'];
setcookie(CART_COOKIE,'',1,"/",$domain,false);
?> <h1 id="reciept">Thank you for your support!</h1><hr> <p id="reciept"> On behalf of LettuceHeadsFarm <?=$tran['full_name']?> we thank you for your purchase and hope you enjoy it! </p>
<p id="reciept"> You have selected <b>"<?=$tran['pickup-location']?>"</b> as your pickup point. </p>
<table id="nav-button" class="table table-bordered table-auto"> <tbody> <tr> <td>Transaction ID : <?=$tran['charge_id']?></td> </tr> <?php $a = 1; $it = 1; $string = $tran['items']; $itemar = explode(',', $string); $num = 1;
$istr = $tran['inventory'];
$stri = explode(',', $istr);
if ($tran['status'] != "Complete") {
foreach (array_slice($stri, $num) as $inve ){
$exploded = explode('.', $inve);
$itname = $exploded['0'];
$itquan = $exploded['1'];
$db->query("UPDATE products
SET `quantity` = `quantity` - '$itquan'
WHERE title = '$itname'");
$db->query("UPDATE products
SET `Sold` = `Sold` + '$itquan'
WHERE title = '$itname'");
$it++;
}
$compl = "Complete";
$db->query("UPDATE transactions
SET `status` = '$compl'
WHERE charge_id = '$trans_id'");
}
foreach (array_slice($itemar, $num) as $itemr ){
?> <tr> <td><?=$itemr?></td> </tr>
<?php $a++; } ?>
<tr> <td> Total: <?=money($tran['grand_total']);?> </td> </tr> </tbody>
</table> <?php }else { echo "Sorry, an error occurred: ".htmlentities($_GET['response_reason_text']); } ?> </div>
<?php include 'includes/rightbar.php'; include 'includes/footer.php'; ?>
补充工具栏代码:
<!-- right side bar-->
<div id="sidebar" class="col-md-2" >
<div class="col-md-12" style="font-size: 75%;">
<ul id="tabs" class="nav nav-pills" role="toolbar">
<li role="presentation">
<a href="#insta"></a>
</li>
<li role="presentation">
<a href="#WHoF"></a>
</li>
<li role="presentation">
<a href="#veggie"></a>
</li>
<li role="presentation">
<a href="#social"></a>
</li>
</ul>
</div>
<br />
<br />
<div class="tabContent" id="insta">
<div class="contentText" id="aboutContent">
<!-- LightWidget WIDGET --> -info removed instagram widget-
</div>
</div>
<div class="tabContent" id="WHoF">
<div id="whoof">
<?php
$sql = "SELECT * from happening ORDER BY post_date desc limit 3 offset 0;";
$result = $db->query($sql);
?>
<?php while($post = mysqli_fetch_assoc($result)) : ?>
<p><b><?=$post['title'];?></b></p>
<hr>
<p ><?= $post['entry']; ?></p>
<hr>
<?php endwhile; ?>
</div>
</div>
<div class="tabContent" id="veggie">
<div>
<p><a href="veggie.php">
<img border="0" alt="Veggie_crate" src="../images/header/veg.png" style="width: 100%; height: 100%;" >
</a></p>
</div>
</div>
<div class="tabContent" id="social">
<div>
-info removed. facebook widget-
</div>
</div>
<script>
$(document).ready(function () {
var timeInterval, tabCount = 0, currnetIndex = 1;
tabCount = $('ul#tabs').find('li a').length;
var tabContentObj = $('.tabContent');
changeTabIndex();
timeInterval = setInterval(function () { changeTabIndex(); }, 6 * 1000);
function changeTabIndex() {
if (currnetIndex > tabCount) {
currnetIndex = 1;
}
tabContentObj.hide();
$('ul#tabs').find('li.selected').removeClass('active');
$('ul#tabs').find('li.selected').removeClass('selected');
var currentAncorObj = $('ul#tabs').find('li a').eq(currnetIndex - 1);
currentAncorObj.parent().addClass('selected');
currentAncorObj.parent().addClass('active');
$(currentAncorObj.attr('href')).show();
currnetIndex++;
};
$('#tabs li').mouseenter(function () {
clearInterval(timeInterval);
}).mouseleave(function () {
timeInterval = setInterval(function () { changeTabIndex(); }, 4 * 1000);
});
$('#tabs li a').click(function () {
tabContentObj.hide();
$('ul#tabs').find('li.selected').removeClass('active');
$('ul#tabs').find('li.selected').removeClass('selected');
var currentAncorObj = $(this);
currnetIndex = $('ul#tabs').find('li a').index($(this)) + 1;
currentAncorObj.parent().addClass('active');
currentAncorObj.parent().addClass('selected');
$(currentAncorObj.attr('href')).show();
currnetIndex++;
//return false;
});
});
</script>
</div>
答案 0 :(得分:0)
尝试生成用户请求的日志,并查看正在进行的操作。
$error_code = uniqid(mt_rand(), true);
file_put_contents(__DIR__ . '/cookie_' . $error_code . '.log', print_r($_REQUEST, 1), FILE_APPEND);
这将让您看到用户在购物车提交期间提供的信息以进行故障排除。 $_REQUEST
包括$_GET
,$_POST
和$_COOKIE
数据。
如果您还没有,那么您还应该测试是否存在$cart_id
,而不是期望它是根据用户的请求提交的。
if (!empty($cart_id) && $_GET['response_code'] == 1) {
$trans_id = (int) $_GET['transaction_id'];
...//
}else{
echo "Sorry, an error occurred (Error Code: " . $error_code . "): ".htmlentities($_GET['response_reason_text']);
}