加载PHP脚本时出现错误500内部服务器错误

时间:2017-08-10 12:32:30

标签: php ajax internal-server-error

我正在构建一个仪表板,其中数据是从db动态收集的。用于获取数据的文件在php中,并且正在使用ajax请求进行调用。但是当我运行脚本时,我收到错误500,内部服务器错误。

我一直试图寻找解决方案几天,但还没有找到任何解决方案。

也许我在代码中忽略了什么?

    include('db/mysqli_con.php');

    // check if the selected year and the user key have been sent 
    if(!empty($_POST["selectYear"]) && !empty($_POST["token"])){

        // Define selected year, start date and end date variables for query
        $year = $_POST["selectYear"];
        $startDate = new DateTime("".$year."-01-01");
        $endDate = new DateTime("".$year."-12-31");
        $token = $_POST["token"];
        $output = '';

        // For every day between start date and end date, define variable $day
        for($day = $begin; $day <= $end; $day->modify('+1 day')) {

        // save date as a string
        $dayString = $day->format("Y-m-d");
        $newDate = "".$dayString." 00:00:00";


        list($y, $m, $d) = explode("-", $dayString);
        // avoid octal values in output
        if($m == 01) {
            $newm = 1;
        }elseif($m == 02) {
            $newm = 2;
        }elseif($m == 03) {
            $newm = 3;
        }elseif($m == 04) {
            $newm = 4;
        }elseif($m == 05) {
            $newm = 5;
        }elseif($m == 06) {
            $newm = 6;
        }elseif($m == 07) {
            $newm = 7;
        }elseif($m == 08) {
            $newm = 8;
        }elseif($m == 09) {
            $newm = 9;
        }else{
            $newm = $m;
        }

    // Check if day is registered in db
    $query = mysqli_query($link, "SELECT * FROM lime_survey_669629 WHERE 
    token = '$token' AND 669629X3X15 = '$newDate'") or die(mysqli_error());

    // start array bracket
    echo '[';

    // define count variable
    $c = mysqli_num_rows($query);

    // check count
    if($c == 0) {

        // if count is 0, register day with value 0
        $output = '['.$y.'-'.$newm.'-'.$d.',0],';
        echo $output;

    }else{

        // if count is more than 0, output datasets
        while($row = mysqli_fetch_array($query)) {

            $oldValue = $row['669629X5X275'];
            $modValue = explode("=", $oldValue);
            $value = $modValue['2'];

            // output dfatasets in a json array
            $output = '['.$y.'-'.$newm.'-'.$d.','.$value.'],';
            echo $output;


        }


           }

         // end array bracket                                                                
         echo ']';

        }

   }

1 个答案:

答案 0 :(得分:0)

首先检查错误的位置 使用error_reporting(E_ALL); ini_set('display_errors',1);

加上标题