【问题标题】:HTTP Error 500 (Internal Server Error) in DrupalDrupal 中的 HTTP 错误 500(内部服务器错误)
【发布时间】:2013-05-14 11:04:38
【问题描述】:

我使用 json 向使用 php 的 ios 应用程序提供数据。但是在浏览器中运行代码时,它显示服务器错误。如果数据库中没有值,则显示代码中提供的{"posts":null}。但是如果数据库中有值,就会出现问题。它显示错误

Server error The website encountered an error while retrieving http://path to the server file/php/categoryitemlisting.php?category=11. It may be down for maintenance or configured incorrectly. Here are some suggestions: Reload this webpage later. HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request. 此错误仅针对此 php 文件发生。使用其他文件,我可以传输数据。

我的 connection.php 文件:

<?php
$link = mysql_connect("127.0.0.1","root","") or die('Cannot connect to the DB');
mysql_set_charset("utf8");
mysql_select_db('cotton',$link) or die('Cannot select the DB');
?>

Categoryitemlisting.php

 <?php

   require('connection.php');
   $item = array()       ;

   /* connect to the db */
      if(isset($_REQUEST['category']))
      {
            $k=$_REQUEST['category'];
        /* grab the posts from the db */
             // $k=11;
            $catid = mysql_query("SELECT entity_id FROM  field_data_field_cat WHERE field_cat_tid= $k");
            while($r = mysql_fetch_assoc($catid))
           {

               $category[] = $r['entity_id'];   
               foreach ( $category as $cat );
              {

                 $data= mysql_query("SELECT field_data_field_name.entity_id, field_data_field_name.field_name_value, file_managed.uri, field_data_field_sec.field_sec_tid FROM file_managed INNER JOIN ( field_data_field_thumb, field_data_field_name, field_data_field_sec ) ON ( file_managed.fid = field_data_field_thumb.field_thumb_fid AND field_data_field_name.entity_id = field_data_field_thumb.entity_id AND field_data_field_thumb.entity_id = field_data_field_sec.entity_id ) WHERE field_data_field_name.entity_id = $cat");  

               $items = mysql_fetch_assoc($data);
               $item[]= $items;
              }
            }
                $re="public:\/\/";
                $list = json_encode(array('posts'=>$item));
            $list = str_replace( $re, "http://localhost/sites/default/files/" ,$list);
                echo $list;

             @mysql_close($link);

      }

      else
      {
      echo "connection failed";
      }
?>

如何通过修复此错误来获取值?我不认为这是服务器的问题。如果代码还有其他错误?

【问题讨论】:

    标签: php drupal-7 phpmyadmin json


    【解决方案1】:

    查看你的 php.ini 并设置:

    display_errors = on
    error_reporting = E_ALL

    如果 display_error 关闭并且您的代码有任何类型的问题(例如:解析错误),您的响应将是 500 状态页面。

    【讨论】:

    • display_errors 和 error_reporting 在我的 php.ini 中都是一样的。但是错误仍然是一样的
    【解决方案2】:

    终于指出了问题....

    服务器代码中的$k=$_REQUEST[' category']; 中有一个空格。这导致了错误。

    【讨论】:

      猜你喜欢
      • 2016-02-14
      • 1970-01-01
      • 1970-01-01
      • 2012-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多