0

I’ve got a PHP file with a switch case to include different files depending on a variable $view.

This was working perfectly when I was running this on WAMP server on my local machine. But now I have uploaded to a web server and the include functions have just stopped working. Nothing is getting included.

switch($view)
    {
    case 'AddToCart':
        echo 'adding to cart';
        if($_POST['qty']>0)
        {
            if(!isset($_SESSION['cart'][$_POST['id']]))
            {
                $_SESSION['cart'][$_POST['id']]=$_POST['qty'];
            }
            else
            {
                $_SESSION['cart'][$_POST['id']]+= $_POST['qty'];
            }   
        }
        header('Location:index.php');
        break;

    case 'UpdateCart':
        echo 'updating cart...';
        if(isset($_SESSION['cart'][$_POST['id']]))
        {
            if($_POST['updateqty']>0)
                $_SESSION['cart'][$_POST['id']]=$_POST['updateqty'];
            else
                unset($_SESSION['cart'][$_POST['id']]);
        }   
        header('Location:index.php?view=ViewCart');
        break;

    case 'ViewCart':
        echo 'This is the full feature cart.';
        include('models\cart.php');
        include('models\fullcart.php');
        break;

    case 'Checkout':
        echo 'reached checkout';
        include('models\finalcart.php');

        break;

    case 'ClearCart':
        echo 'Clear cart reached';
        $_SESSION['cart']=array();
        $_SESSION['total_items']=0;
        $_SESSION['total_price']=0;
        header('Location:index.php');
        break;

    case 'RemoveItem':
        echo 'Removing item '.$_POST['id'].'<br><br>';
        unset($_SESSION['cart'][$_POST['id']]);
        header('Location:index.php?view=ViewCart');
        break;

    default:
        echo 'index page...lalalalalal...<br>';
        include('models\cart.php');
        include('models\catalog.php');
    }

I did phpinfo on the webserver and found it’s running PHP version 5.2.17.

Whats going wrong?

2
  • Are the files there in the correct paths? Do they have the correct permissions? Do you get any error/warning messages? Commented Mar 6, 2011 at 10:45
  • Off the top of my head, this could be a directory separator issue since Window uses \ and Unix /. However, have you got your error reporting turned on? Commented Mar 6, 2011 at 10:47

3 Answers 3

3

Hope you know not to echo/print anything before you send headers. And can you check what your server os is, I use /, not \, in file paths

Sign up to request clarification or add additional context in comments.

1 Comment

yes that was it the slashes... many thanks good sir... my stupidity, the slashes are the first thing i should have checked but it never occurred to me that there may be a problem with the slashes...
2

I guess your web server is running linux or another unix-like system, which uses forward slashes instead of backslashes as directory seperator. So you have to replace the slashes in the include paths:

include('models\fullcart.php');

becomes

include('models/fullcart.php');

and so on...

Comments

1

check the included file permissions i think they should be 755 or 775

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.