簡體   English   中英

PHP調用中的500 Internal Server Error

[英]500 Internal Server Error on PHP calls

當我使用$.ajax請求php文件時,我總是遇到此問題,它總是返回500服務器錯誤,但僅當我將文件上傳到服務器時才出現。 我在Windows 8.1和localhost上完美運行XAMPP。

我已經嘗試直接訪問php文件的網址,也給了我同樣的錯誤。

阿賈克斯

function get_blog(reload_list){
    var $titulo, $texto, $response, $post, $post_list;
    var parameters = window.location.search;
    $.ajax({
        method: 'get',
        url: '/php/blog.php' + parameters,
        success: function(data){
            if(data == "404"){
                $("#blog").html("404 El articulo que buscas no existe");
            } else {
                $response = data;
                $post_list = $response.post_list;
                $titulo = $response.post.titulo;
                $texto =  $response.post.texto;
                $("title#blog_title").html("IBR - " + $titulo);
                $("h3#blog_title").html($titulo);
                $("#blog_text").html($texto);

                if(reload_list){
                    for(i=0; i<=$post_list.length; i++){
                        $("#post_list").append($post_list[i]);
                    }
                }
            }
        }
    });

PHP的

<?php
error_reporting(E_ALL);
ini_set('display_errors' 1); 

$l =  mysql_connect ( "localhost" , "myserver" , "mypass" ) or die("Error connecting:<BR><BR>".mysql_error());

mysql_select_db( "mydb" ) or die("Error getting db:<BR><BR>".mysql_error()); 
if(!isset($_GET['post_id'])) {
    $query = mysql_query("SELECT * FROM mytable ORDER BY id DESC LIMIT 1") or die(mysql_error());
    $row = mysql_fetch_array($query);
    $id = stripslashes($row['id']); 
    $titulo = stripslashes($row['titulo']); 
    $texto = stripslashes($row['texto']); 

    $post = [
            'id' => $id,
            'titulo' => $titulo,
            'texto' => $texto
    ];

}else{
    // echo $_GET['post_id'];
    $post_id = $_GET['post_id'];
    $query = mysql_query("SELECT * FROM mytable WHERE id=$post_id ORDER BY id DESC LIMIT 1") or die(mysql_error());
    $row = mysql_fetch_array($query);
    if(empty($row)){
        die("404");
    }
    $id = stripslashes($row['id']); 
    $titulo = stripslashes($row['titulo']); 
    $texto = stripslashes($row['texto']); 


    $post = [
            'id' => $id,
            'titulo' => $titulo,
            'texto' => $texto
    ];
}


$query = mysql_query("SELECT * FROM mytable ORDER BY id DESC") or die(mysql_error());
while ($row = mysql_fetch_array($query) )
{

    $id = stripslashes($row['id']); 
    $titulo = stripslashes($row['titulo']); 

    $li = '<a class="text_decoration post_list_item" href="devocional.html?post_id='.$id.'"><li>'.$titulo.'</li></a>';

    $post_list[]= $li;
}

$response = [
    'post' => $post,
    'post_list' => $post_list
];

$json_response = json_encode($response);
print_r($json_response);
?>

實際上,我無法訪問我的error_log 還嘗試通過以下方式查看錯誤:

error_reporting(E_ALL);
ini_set('display_errors' 1);

但是瀏覽器僅顯示空白頁。 我在使用PHP SDK的Facebook API調用中也遇到了同樣的問題。 我真的不知道該怎么辦。 感謝您的提前幫助。

PHP直到5.4才支持當前使用的速記數組。 http://php.net/manual/en/migration54.new-features.phphttp://php.net/manual/en/language.types.array.php

這是您的更新代碼,該代碼應該可以正常工作並與5.6向前兼容。

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

$l =  mysql_connect ( "localhost" , "myserver" , "mypass" ) or die("Error connecting:<BR><BR>".mysql_error());

mysql_select_db( "mydb" ) or die("Error getting db:<BR><BR>".mysql_error()); 
if(!isset($_GET['post_id'])) {
    $query = mysql_query("SELECT * FROM mytable ORDER BY id DESC LIMIT 1") or die(mysql_error());
    $row = mysql_fetch_array($query);
    $id = stripslashes($row['id']); 
    $titulo = stripslashes($row['titulo']); 
    $texto = stripslashes($row['texto']); 

    $post = array(
            'id' => $id,
            'titulo' => $titulo,
            'texto' => $texto
    );

}else{
    // echo $_GET['post_id'];
    $post_id = $_GET['post_id'];
    $query = mysql_query("SELECT * FROM mytable WHERE id=$post_id ORDER BY id DESC LIMIT 1") or die(mysql_error());
    $row = mysql_fetch_array($query);
    if(empty($row)){
        die("404");
    }
    $id = stripslashes($row['id']); 
    $titulo = stripslashes($row['titulo']); 
    $texto = stripslashes($row['texto']); 


    $post = array(
            'id' => $id,
            'titulo' => $titulo,
            'texto' => $texto
    );
}


$query = mysql_query("SELECT * FROM mytable ORDER BY id DESC") or die(mysql_error());
while ($row = mysql_fetch_array($query) )
{

    $id = stripslashes($row['id']); 
    $titulo = stripslashes($row['titulo']); 

    $li = '<a class="text_decoration post_list_item" href="devocional.html?post_id='.$id.'"><li>'.$titulo.'</li></a>';

    $post_list[]= $li;
}

$response = array(
    'post' => $post,
    'post_list' => $post_list
);

$json_response = json_encode($response);
print_r($json_response);
?>

另外,這里的強制性說明...

  1. 將您的SQL驅動程序從mysql_更改為mysqli或PDO。
  2. 從查詢中分離出用戶輸入,或者至少使用mysql_real_escape_string(該函數名稱可能會按順序反轉)。 您當前對SQL注入開放。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM