1
我應該如何處理這種情況下的兩種可能的錯誤?我不確定這是否是推薦的方式,請有人建議?我用這個json_encode()正確處理了錯誤嗎?
if (isset($_GET['numberofwelds']) && isset($_GET['numberofconwelds'])
{
// Now we know both values definitely exist, VALIDATE them
$numwelds = $_GET['numberofwelds'];
$numconwelds = $_GET['numberofconwelds'];
if (is_int($numwelds) && is_int($numconwelds))
{
// Calculate your total
$total = $numwelds + $numconwelds;
echo json_encode($total);
}
else
{
$response = array("status" => "failure", "message" => "GET params were not numbers");
echo json_encode($response);
}
else
{
$response = array("status" => "failure", "message" => "GET params do not exist");
echo json_encode($response);
}
}
你應該編碼爲json的錯誤響應。現在你顯然在第一個IF和最後一個ELSE之間缺少一個括號 –
好吧,所以你編輯了你的代碼,但是你使用了哪些代碼?你至少試過嗎?那麼你的問題是什麼? –
處理兩個錯誤是什麼意思?當然,一次只能遇到一個錯誤,就像上面說的那樣,你應該編碼爲JSON這些$回覆 –