php给出一个空白页,没有错误

标签 php mysql ajax mysqli

我有一个 AJAX 应用程序的以下部分,它没有给出任何错误,但屏幕上也没有显示任何内容,所以我不确定问题出在哪里。使用 ?cmd&id=1 直接从浏览器调用此页面应该返回,甚至不使用 ?cmd 调用它应该返回 cmd 错误消息。

编辑:添加的测试用例:我确实收到了 cmd 错误消息,但是当我传递 &id=1(1 是有效 ID)时,没有返回任何 html,查看源代码完全空白。我是否错误地使用了 echo 或类似的东西?

edit2: 添加 echo 作为第一行:第一个 echo 无论如何都看不到

edit3:回到旧版本并再次进行所有更改后,我现在在使用有效的 cmd 和 id 参数调用时得到测试字符集输出。我使用的代码与下面粘贴的代码相同。

代码:

<?php
echo "hello world";    
error_reporting(E_ALL);

if (isset($_GET["cmd"]))
  $cmd = $_GET["cmd"];
else
  die("You should have a 'cmd' parameter in your URL");

$id = $_GET["id"];

$con = mysqli_connect("localhost", "user", "password", "db");
echo "test con";

if(!$con)
{
  die('Connection failed because of' .mysqli_connect_error());
  echo "test error";
}

//$con->query("SET NAMES 'utf8'"); 
$con->set_charset("utf8"));
echo "test charset";

if($cmd=="GetSALEData")
{
  echo "test cmdifloop";

  if ($getRecords = $con->prepare("SELECT * FROM SALES WHERE PRODUCT_NO = ?"))
  {
    echo "test recordifloop";

    $getHtml = $con->prepare("SELECT PRODUCT_DESC FROM SALES WHERE PRODUCT_NO = ?");
    $getHtml->bind_param("s", $id);
    $getHtml->execute();
    $getHtml->bind_result($PRODUCT_DESC);

    $getRecords->bind_param("s", $id);
    $getRecords->execute(); 
    $getRecords->bind_result($PRODUCT_NO, $PRODUCT_NAME, $SUBTITLE, $CURRENT_PRICE, $START_PRICE,
                             $PRICE_COUNT, $QUANT_TOTAL, $QUANT_SOLD, $ACCESSSTARTS, $ACCESSENDS,
                             $ACCESSORIGIN_END, $USERNAME, $BEST_PRICEDER_ID, $FINISHED, $WATCH,
                             $BUYITNOW_PRICE, $PIC_URL, $PRIVATE_SALE, $SALE_TYPE, $ACCESSINSERT_DATE,
                             $ACCESSUPDATE_DATE, $CAT_DESC, $CAT_PATH, $COUNTRYCODE, $LOCATION,
                             $CONDITIONS, $REVISED, $PAYPAL_ACCEPT, $PRE_TERMINATED, $SHIPPING_TO,
                             $FEE_INSERTION, $FEE_FINAL, $FEE_LISTING, $PIC_XXL, $PIC_DIASHOW,
                             $PIC_COUNT, $ITEM_SITE_ID
                            ); 
    while ($getRecords->fetch()) 
    {
      $ccodes = array(  "1" => "USA",
                       "77" => "Germany",
                       "16" => "Austria",
                      "122" => "Luxemburg",
                      "193" => "Switzerland",
                     );

      $conditions = array( "0" => "USA",
                          "77" => "Germany",
                          "16" => "Austria",
                         );

      $country = $ccodes[$COUNTRYCODE];
      if ( $country == "" ) $country = "Not applicable";

      $columns = array('FINISHED', 'WATCH', 'PRIVATE_SALE', 'REVISED', 'PAYPAL_ACCEPT', 'PRE_TERMINATED', 'PIC_XXL', 'PIC_DIASHOW');

      foreach($columns as $column) {
        $$column = $row[$column] ? 'YES' : 'NO';
      }

      imageResize($PIC_URL, 250, 300);
      file_put_contents($id, file_get_contents($PIC_URL));

      $html = htmlentities(json_encode($PRODUCT_DESC));
      $shortDate = strftime("%d %m %Y", strtotime($ACCESSSTARTS));

      echo "<h1>".$PRODUCT_NAME."</h1>
<div id='leftlayer' class='leftlayer'>
<p><strong>Username: </strong>".$USERNAME."
<p><strong>PRODUCT Number: </strong>".$PRODUCT_NO."
<p><strong>Subtitle: </strong>".$SUBTITLE."
<p><strong>SALE Start: </strong>".$ACCESSSTARTS." 
<p><strong>SALE End: </strong>".$ACCESSENDS."
<p><strong>SALE Type: </strong>".$SALE_TYPE."
<p><strong>Category: </strong>".$CAT_DESC."
</div>
<div class='leftlayer2'>
  <p><strong>Condition: </strong> ".$CURRENT_PRICE."
  <p><strong>Total Items: </strong> ".$QUANT_TOTAL."
  <p><strong>Total Sales: </strong> ".$QUANT_SOLD."
  <p><strong>Start Price: &#8364</strong> ".$START_PRICE."
  <p><strong>Buyitnow Price: &#8364</strong> ".$BUYITNOW_PRICE."
  <p><strong>PRICEs: </strong> ".$PRICE_COUNT." 
  <p><strong>Revised: </strong> ".$REVISED."
</div>
<div class='leftlayer2'>
  <p><strong>Private: </strong> ".$PRIVATE_SALE."
  <p><strong>Finished: </strong> ".$FINISHED."
  <p><strong>Cancelled: </strong> ".$PRE_TERMINATED."
  <p><strong>Paypal: </strong> ".$PAYPAL_ACCEPT."
  <p><strong>Country: </strong> ". $country ."
  <p><strong>Location: </strong> ".$LOCATION."
  <p><strong>Shipping to: </strong> ". $country ."
</div>
<div id='rightlayer'>
 <img src='".$PIC_URL."' width='".$imageSize["width"]."' height='".$imageSize["height"]."'>
 <p><a href='#' onclick=\"makewindows(" . $html . "); return false;\">Click for full description </a></p>
</div>
</div>
</div>";

    } 
  }

  function imageResize($imageURL, $maxWidth, $maxHeight)
  {
    $imageSize["width"] = 0;
    $imageSize["height"] = 0;

    $size = getimagesize($imageURL);
    if ($size) {
      $imageWidth  = $size[0];

      $imageHeight = $size[1];
      $wRatio = $imageWidth / $maxWidth;
      $hRatio = $imageHeight / $maxHeight;
      $maxRatio = max($wRatio, $hRatio);

      if ($maxRatio > 1) {
        $imageSize["width"] = $imageWidth / $maxRatio;
        $imageSize["height"] = $imageHeight / $maxRatio;
        return $imageSize;
      } else {
        $imageSize["width"] = $imageWidth;
        $imageSize["height"] = $imageHeight;
        return $imageSize;
      }
    } else {
      die(print_r(error_get_last()));
    }
  }

}

我为间距道歉,但当我按下代码按钮时它会自动发生。

最佳答案

这将帮助您查看错误:

ini_set('display_errors', '1');

关于php给出一个空白页,没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/487301/

相关文章:

javascript - 使用 php 用 js 创建警报

ajax - 在rails 3上具有will_paginate的排序表

mysql - 如何阻止 Rails 转义 SQL 中特定列的值?

javascript - 在表单提交时将客户端 HTML 表数据提取到服务器端 PHP 脚本

php - 无需 jQuery 或其他框架即可动态刷新带有表格的 div

php - APC - 如何处理 GC 缓存警告?

php - 增加 Google App Engine 中的执行时间限制

PHP 在命令行中获取多个参数

mysql - SORM 和 trait 作为字段类型

java - 使用 MySQL 中的数据填充 JComboBox