开发者

php not well formed?

when my site loads, it stops half way because of specific php code. When I try commenting out the php code, the whole page loads properly (input boxes, buttons etc.)

This is the code that causes the issue

<?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();
        ?>


I doubt it's malformed code (a parser error) - I'd recommend turning on error reporting so you can see the error on screen, or inspect your apache error logs. That will likely show some runtime error. Without the error, or the code of the deleteItem, saveInstance, listItems functions, it's impossible to say.


Silly answer but, I was not importing my classes properly. So once a Object tried to instantiate from another class, anything below that instantiation broke.

Code was lacking an include_once()

Hope that helps all the newbies out there!


Newbies, and experienced developer too, should allways put

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

at the top of the php main file, while developing on the dev server..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜