【问题标题】:php not well formed?php格式不正确?
【发布时间】:2010-05-18 02:13:48
【问题描述】:

当我的网站加载时,由于特定的 php 代码,它会在中途停止。当我尝试注释掉 php 代码时,整个页面正确加载(输入框、按钮等)

这是导致问题的代码

<?php
        //if the add location button is clicked, the add location, the whole form will not be submitted
            if($_REQUEST['command'] == 'Add'){
                if($_POST['companyLocation'] == ""){
                    $errmsg="Please enter a location1";
                }
                elseif($_POST['companySize'] == ""){
                    $errmsg="Please enter a size for the location";
                }
                else{
                    $location = Location::instance();

                    $testing = $location->doesExist($_POST['companyLocation']);
                    if ($testing == true){
                        $errmsg="Location already exists";
                    }
                    else{
                        $objLocation = new Obj_Location();
                        $objLocation->set_Name($_POST['companyLocation']);
                        $objLocation->set_Size($_POST['companySize']);
                        $location->addLocation($objLocation);
                        $location->saveInstance();
                    }
                }
            }

//this is the part that breaks! when I comment it out, the page loads properly.
        $location = Location::instance();
        $location->deleteItem($_GET["item"]);
        $location->saveInstance();
        $location->listItems();
        ?>

【问题讨论】:

  • 你得到什么错误?
  • 其实PHP语法没问题。也许你应该看一下日志,这样你就知道出了什么问题。
  • 愚蠢的问题,但是如何在ubuntu中读取apache的错误日志?而且我只能ssh,所以我只使用命令行。
  • 除非 Apache 被修改为将日志发送到别处,它应该在 /var/log/httpd/error.log
  • 有谁知道我的编码方法是否是 php 5.2.10 的“新”方法?阻塞代码的服务器是 php5.2.4。只是我注意到的一个差异......

标签: php xhtml


【解决方案1】:

我怀疑这是格式错误的代码(解析器错误) - 我建议打开错误报告,以便您可以在屏幕上看到错误,或检查您的 apache 错误日志。这可能会显示一些运行时错误。没有错误,或者deleteItemsaveInstancelistItems函数的代码,就没法说了。

【讨论】:

  • 如果我注释掉最后 3 行并离开实例,我仍然会收到错误消息。例如,这是代码。公共静态函数实例($args = null){ 返回空($_SESSION['locations'])?新位置($args):反序列化($_SESSION['locations']); }
【解决方案2】:

愚蠢的回答,但是我没有正确导入我的课程。因此,一旦一个 Object 试图从另一个类实例化,任何低于该实例化的东西都会中断。

代码缺少 include_once()

希望对所有新手有所帮助!

【讨论】:

  • 错误日志可以帮助新手。比整个月的代码审查要快得多。
  • 开启 error_reporting 会让调试更容易!
【解决方案3】:

新手和经验丰富的开发人员也应该始终投入使用

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

在 php 主文件的顶部,在开发服务器上开发时..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-27
    • 2010-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多