0

I've an internal server error and I think switch statement is the cause, because before adding it, I had not. Someone could help me please? Maybe using if construct I can resolve?

part of my main.php :

$.ajax({ 
    type: "POST", 
    url: "callFunc.php", 
    data: { ciccio: app , alt:h , bas:b , spe:p }, 
    success: function(msg) {
        alert( "done!"+msg );
    }
});

part of my callFunc.php :

$lav = $_REQUEST['ciccio'];
$alt = $_REQUEST['alt'];
$bas = $_REQUEST['bas'];
$spe = $_REQUEST['spe'];

switch ($lav){

    case 'uno' :
    case 'due' :

        echo call_user_func('getPrice_'.$lav,$alt) ;
        break;

    case 'tre' :
    case 'quattro' :

        echo call_user_func('getPrice_'.$lav,$bas) ;
        break;

    case 'cinque' :
    case 'sei' :

        echo call_user_func('getPrice_'.$lav,$bas,$spe) ;
        break;

    default :
        echo 'ERROR : Unexpected value!'    

}
  • 4
    A "500 Internal Server Error" status code (or a blank page) means that your script is throwing an error but you haven't configured PHP to display error messages. That's something you need to fix before you go further; it's impossible to code properly without the aid of error messages. Here's a [brief explanation](http://stackoverflow.com/a/5680885/13508). The error reporting thumb rule is: show in development, log in production. – Álvaro González Dec 17 '14 at 17:45
  • 2
    You have missed a `;` in the `default` case `echo`. That's the first thing I spot, there may be more. Enable `display_errors` as suggested by @ÁlvaroG.Vicario – Michael Berkowski Dec 17 '14 at 17:47
  • 1
    Last line, the `echo` is not terminated with a `;`. – Boldewyn Dec 17 '14 at 17:48
  • Or, at least, you need to go look in your server's error log, where you'll be able to read the actual error, rather than guessing from a blank page. – Matt Gibson Dec 17 '14 at 17:50
  • How many of these typo questions are we gonna see here on StackOverflow. Man... – Klemen Tusar Dec 17 '14 at 17:54
  • What do your error logs state? Error logs tell you information about errors, which is extremely useful when you have an error, and you do not know what the error is. You've posted here to ask us what the error in your code is, when your error log will already have the answer for you. Really, error logs are invaluable when coding. Did I mention you should make use of your error logs? – James Dec 17 '14 at 17:57

2 Answers2

1

you have error here: 500 error means code got some problem.if you are using eclipse or something you will get red * mark in that row.

 default :
        echo 'ERROR : Unexpected value!'  

use ;.

Suchit kumar
  • 11,809
  • 3
  • 22
  • 44
0

in callFunc.php use

$input = file_get_contents('php://input');
$input = json_decode($input);
$lav = $input->ciccio;
$alt = $input->alt;
$bas = $input->bas;
$spe = $input->spe;