0

当我想在服务器上测试我的文件时,我收到了一个错误(500 内部服务器错误)。mamp(本地)一切正常,我没有收到任何错误。这是有错误的代码。

<?php
    include_once('../classes/places.class.php');
try
{
    $oPlace = new Places();
    $oPlace->Street = $_POST['place'];
    $oPlace->HouseNumber = $_POST['number'];
    $oPlace->Name = $_POST['Name'];
    if($oPlace->placeAvailable())
    {
        $feedback['status'] = "success";
        $feedback['available'] = "yes";
        $feedback["message"] = "Go ahead, street is available";
    }   
    else
    {
        $feedback['status'] = "success";
        $feedback['available'] = "no";
        $feedback["message"] ="De zaak " . "'" . $_POST['name'] . "'". " is reeds op dit adres gevestigd." ;;
    }
}
catch(exception $e)
{
    $feedback['status'] = "error";
    $feedback["message"] =$e->getMessage();

}
header('Content-type: application/json');
echo json_encode($feedback);
?>
4

3 回答 3

1

它是什么版本的 PHP?

如果在 5.2 之前,您需要安装 JSON PECL 包。

如果是 5.20 或更高版本,您必须检查 PHP 是否在没有该--disable-json选项的情况下编译。

于 2012-05-05T11:28:56.543 回答
0
$feedback["message"] ="De zaak " . "'" . $_POST['name'] . "'". " is reeds op dit adres gevestigd." ;;

应该更像

$feedback["message"] ="De zaak " . "'" . $_POST['name'] . "'". " is reeds op dit adres gevestigd." ;

添加过多的分号有时会引发错误

于 2012-05-05T11:24:01.347 回答
-1
<?php
include_once('../classes/places.class.php');
/* This if for debugging */
foreach ($_GET as $k => $v) $_POST[$k] = $v;
// Access in your browser: pathToFilePHPCalled.php?place=SomePlace&number=14&Name=MyName
$feedback['data'] = $_POST;
/* This if for debugging */

$feedback = array();
try
{
    $oPlace = new Places();
    $oPlace->Street = $_POST['place'];
    $oPlace->HouseNumber = $_POST['number'];
    $oPlace->Name = $_POST['Name']; // Make sure this is $_POST['Name'] and not $_POST['name'] this might be your error
    if($oPlace->placeAvailable())
    {
        $feedback['status'] = "success";
        $feedback['available'] = "yes";
        $feedback["message"] = "Go ahead, street is available";
    }   
    else
    {
        $feedback['status'] = "success";
        $feedback['available'] = "no";
        $feedback["message"] ="De zaak " . "'" . $_POST['name'] . "'". " is reeds op dit adres gevestigd." ;
    }
}
catch(Exception $e)
{
    $feedback['status'] = "error";
    $feedback["message"] =$e->getMessage();

}
header('Content-type: application/json');
echo json_encode($feedback);
?>
于 2012-05-05T11:29:39.570 回答