tags:

views:

82

answers:

3

Hi Everyone, 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();
        ?>
+2  A: 

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.

nickf
if i comment out the last 3 lines, and leave instance, I'll still get the error. here's the code for instance. public static function instance($args = null) { return empty($_SESSION['locations']) ? new Location($args) : unserialize($_SESSION['locations']); }
Idealflip
A: 

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!

Idealflip
Error log can help newbies. Way faster than whole month of code reviewing.
Col. Shrapnel
turning error_reporting on would make debugging a lot easier!
Rob
A: 

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..

DaNieL