PHP GET, if / esle [closed]

南笙酒味 提交于 2019-12-11 15:37:56

问题


What's wrong with this code:

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

I get an internal server error.


回答1:


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




回答2:


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




回答3:


Semicolon is missing in else part $variable.

else {
    $variable = "b"; 
}



回答4:


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




回答5:


Mising a semicolon

$variable = "b";



回答6:


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.




回答7:


Propably the missing ; in line 6

    $variable = "b";

Because some other answer provide alternatives too

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

:)



来源:https://stackoverflow.com/questions/6447597/php-get-if-esle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!