PHP GET, if / esle [closed]

2019-09-15 03:17发布

What's wrong with this code:

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

I get an internal server error.

7条回答
Evening l夕情丶
2楼-- · 2019-09-15 03:34

Semicolon is missing in else part $variable.

else {
    $variable = "b"; 
}
查看更多
狗以群分
3楼-- · 2019-09-15 03:36
<?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

查看更多
家丑人穷心不美
4楼-- · 2019-09-15 03:38

Mising a semicolon

$variable = "b";
查看更多
我只想做你的唯一
5楼-- · 2019-09-15 03:45

Propably the missing ; in line 6

    $variable = "b";

Because some other answer provide alternatives too

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

:)

查看更多
做个烂人
6楼-- · 2019-09-15 03:57

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

查看更多
淡お忘
7楼-- · 2019-09-15 03:57

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

查看更多
登录 后发表回答