开发者

PHP GET, if / esle [closed]

开发者_如何学C This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 10 years ago.

What's wrong with this code:

<?php
if ($_GET['variable'] == "a") {
    $variable = "a";
}
else {
    $variable = "b" 
}
echo $variable;
?>

I get an internal server error.


You missed a semicolon here: $variable = "b";


<?php
$variable = 'b';
if (isset($_GET['hop']) && $_GET['hop'] == "a")
{
    $variable = 'a';
}

echo $variable;
?>

For an explanation on what you did wrong look here: http://php.net/manual/en/getting-started.php


Semicolon is missing in else part $variable.

else {
    $variable = "b"; 
}


You forgot the trailing ; on the $variable = "b" line.


Mising a semicolon

$variable = "b";


Missing a semi-colon does not give an internal server error. Check to see if you have a .htaccess file in the root and if its configured correctly.


Propably the missing ; in line 6

    $variable = "b";

Because some other answer provide alternatives too

echo isset($_GET['hop']) && ($_GET['hop'] == "a")
     ? 'a'
     : 'b';

:)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜