duanjuelu8874 2016-06-03 16:23
浏览 29

SQL在一些机器上的一个页面中失败

Edit: Forgot to mention none of the SQL works at all when it fails.

I seriously need help figuring this out. It has been about a month since the issue has arrived. I have rewrote the page a couple times and have tried removing some unneeded items in case it was a speed issue (had sidebar that auto scrolled and loaded in two social media widgets which was kinda slow on bad internet) and so far nothing. I really do not know why this happens at all.

Here is the kicker. It only happens to random people. Never breaks for me but breaks nearly every time for a customer on certain pc's. Another issue that person is running into is the cart cookie won't clear for that person either(just them).

I am Using Auth.net's DPM method which takes them offsite momentarily then to my Order_receipt page(the one in question). When arriving at that page you are given 2 $_GET properties example (order_receipt.php?response_code=1&transaction_id=136434353) which is coming in properly even when it fails.

Customer that has issue is using win 10, and has tried it with both chrome and edge running kaspersky antivirus (no issues on my end from either browser)

I'm going to include all code loaded and included in that page below, starting with the order_receipt itself.

** = redacted info

Order_receipt.php:

<?php
require_once 'system/init.php';
include 'includes/head.php';
include 'includes/navigation.php';
include 'includes/headerpartial.php';

?>

<div id="maincontent" class="col-md-12">

<?php
ini_set('error_reporting', -1); ini_set('display_errors', 'on');

ini_set('log_errors', 1);

ini_set('error_log', 'system/error_logs.log');

$error_code = uniqid(mt_rand(), true);




if ($_GET['response_code'] == 1)
{



  $trans_id = $_GET['transaction_id'];

  if (isset($cart_id)){


  $db->query("UPDATE transactions SET charge_id = '$trans_id' WHERE cart_id = '$cart_id'");




  $tsql = $db->query("SELECT * FROM transactions WHERE cart_id = '$cart_id' ");
  $tran = mysqli_fetch_assoc($tsql);




?>
<h1 id="reciept">Thank you for your support!</h1><hr>
<p id="reciept">
 On behalf of ** <?=$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 cart_id = '$cart_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
  $domain = '.'.$_SERVER['HTTP_HOST'];
setcookie(CART_COOKIE,'',1,"/",$domain,false);


}else{echo "Cart Id not Set";}



}else
{
echo "Sorry, an error occurred: ".htmlentities($_GET['response_reason_text']);
}?>

</div>


<?php

include 'includes/footer.php';
?>

Init.php:

<?php
$db = mysqli_connect("**","**","**","**");
if(mysqli_connect_errno()){
  echo 'Database connection failed with following errors: '. mysqli_connect_error();
  die();
}
session_start();
require_once $_SERVER['DOCUMENT_ROOT'].'/config.php';
require_once BASEURL.'helpers/helpers.php';

$cart_id = '';
if(isset($_COOKIE[CART_COOKIE])){
  $cart_id = sanitize($_COOKIE[CART_COOKIE]);
}

if (isset($_SESSION['LHUser'])) {
  $user_id = $_SESSION['LHUser'];
  $query = $db->query("SELECT * FROM users WHERE id = '$user_id'");
  $user_data = mysqli_fetch_assoc($query);
  $fn = explode(' ', $user_data['full_name']);
  $user_data['first'] = $fn[0];
  $user_data['last'] = $fn[1];
}

if (isset($_SESSION['success_flash'])) {
  echo '<div class="bg-success"><p class="text-success text-center">'.$_SESSION['success_flash'].'</p></div>';
  unset($_SESSION['success_flash']);
}


if (isset($_SESSION['error_flash'])) {
  echo '<div class="bg-danger"><p class="text-danger text-center">'.$_SESSION['error_flash'].'</p></div>';
  unset($_SESSION['error_flash']);
}



 ?>

config.php:

<?php
define('BASEURL', $_SERVER['DOCUMENT_ROOT'].'/');
define('CART_COOKIE','Sd4CqdgRt6J3gd3F7');
define('CART_COOKIE_EXPIRE', time() + (86400 * 30));

 ?>

helpers.php:

<?php
ob_start();
function display_errors($errors){
  $display = '<ul class="bg-danger">';
  foreach ($errors as $error) {
    $display .= '<li class="text-danger">'.$error.'</li>';
  }
  $display .= '</ul>';
  return $display;
}

function sanitize($dirty){
  return htmlentities($dirty,ENT_QUOTES,"UTF-8");

}

function money($number){
  return '$'.number_format($number,2);
}

function login($user_id){
  $_SESSION['LHUser'] = $user_id;
  global $db;
  $date = date("Y-m-d H:i:s");
  $db->query("UPDATE users SET last_login = '$date' WHERE id = '$user_id'");
  $_SESSION['success_flash'] = 'You are now logged in!';
  header('Location: index.php');
}

function is_logged_in(){
  if (isset($_SESSION['LHUser']) && $_SESSION['LHUser'] > 0) {
    return true;
  }
  return false;
}


function login_error_redirect($url = 'login.php'){
  $_SESSION['error_flash'] = 'You must be logged in to access that page';
  header('Location:'.$url);
}

function permission_error_redirect($url = 'login.php'){
  $_SESSION['error_flash'] = 'You don\'t have permission to access that page';
  header('Location:'.$url);
}


function has_permission($permission = 'admin'){
  global $user_data;
  $permissions = explode(',', $user_data['permissions']);
  if (in_array($permission,$permissions,true)) {
    return true;
  }
  return false;
}


function get_category($child_id){
  global $db;
  $id = sanitize($child_id);
  $sql = "SELECT p.id AS 'pid', p.category AS 'parent', c.id AS 'cid', c.category AS 'child'
          FROM categories c
          INNER JOIN categories p
          ON c.parent = p.id
          WHERE c.id = '$id'";
  $query = $db->query($sql);
  $category = mysqli_fetch_assoc($query);
  return $category;

}

head.php:

<!DOCTYPE html>
<html>
<head>
  <title>LettuceHeads</title>
  <link rel="stylesheet" href="css/bootstrap.min.css">
  <link rel="stylesheet" href="css/main.css">
  <link rel="icon" href="../images/header/logoicon.png">
  <meta name="Viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  <script SRC="js/bootstrap.min.js"></script>
</head>
<body>


  <div id="fb-root"></div>
  <script>(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.6";
    fjs.parentNode.insertBefore(js, fjs);
  }(document, 'script', 'facebook-jssdk'));</script>

navigation.php:

<?php
$sql = "SELECT * FROM navigation ORDER BY `navigation`.`sort` ASC";
$pquery = $db->query($sql);
 ?>

<nav id="navbar" class="navbar navbar-default navbar-fixed-top" role="navigation">
 <div id="navtext" class="containter">
   <a id="navborder" href="index.php" class="navbar-brand">**</a>
  <ul class="nav navbar-nav">
    <?php while($parent = mysqli_fetch_assoc($pquery)) : ?>
    <li id="navborder"><a href="<?=$parent['url'];?>"><?=$parent['name'];?></a></li>
    <?php endwhile; ?>

    </li>

  </ul>
  <ul  id="navright" class="nav navbar-nav navbar-right" >

    <li id="navborder2"><a href="cart.php"><span class = "glyphicon glyphicon-shopping-cart"></span> My Cart</a></li>
  <?php  if(has_permission('admin')): ?>
      <li id="navborder"><a href="admin/index.php">Staff</a></li>
  <?php endif; ?>
</ul>

 </div>
</nav>

headerpartial.php:

<div id="partialHeaderWrapper">
  <div id="partialbackitem"></div>
  <div id="partiallogotext"></div>
  <div id="partialfore-item"></div>
</div>

<div class="container-fluid">

footer.php:

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图