Php is poorly formed?

when my site loads it stops halfway due to specific PHP code. When I try to comment out the PHP code, the whole page loads correctly (input fields, buttons, etc.)

This is the code causing the problem

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

      

+2


a source to share


3 answers


Silly answer, but I didn't import my classes correctly. Therefore, as soon as the object tried to instantiate from another class, everything below that instance broke.

There was no include_once () in the code



Hope it helps all newbies!

0


a source


I doubt it has corrupted the code (parser error). I would recommend turning on error reporting so you can see the error on screen or check your apache error logs. This will probably lead to some kind of runtime error. Without error or function code deleteItem

, saveInstance

, listItems

it is impossible to say.



+2


a source


Newbies and seasoned developers should always post

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

      

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

0


a source







All Articles