0

I'm told to do this

If the user has entered both names and checked a radio button, show a greeting Hello <firstname> <lastname>. Change the background color of the Web page to the selected color. You do this by using the echo statement as follows:

echo "<body bgcolor =\” $color\”&gt; Hello $firstname $lastname";

and my other php file I have

elseif(!(empty($_GET["fname"])) && (!(empty($_GET["lname"]))) && ($_GET["bgcolor"] == "red"))
{
echo "<body bgcolor='red'>" . "Hello " . $_GET["fname"] . " ". $_GET["lname"] . "!<br/>" . "Background color changed to the selected color";
}

is it possible if I put the the $_GET["bgcolor"]'s value into the <body bgcolor=''>? so I don't have to use another elseif statement...

because seeing this

echo "<body bgcolor =\” $color\”&gt; Hello $firstname $lastname";

lets me think it's possible but if with just one variable $color how is that possible O.o

4

3 回答 3

1

好吧,当然是。但是你为什么不自己尝试一下呢?将花费更少的时间来发布这个问题。:)

例如这样的:

$default_color = "white";
[...]
if(!(empty($_GET["fname"])) && (!(empty($_GET["lname"])) && (!(empty($_GET["bgcolor"])))
{
  echo "<body bgcolor=". $_GET["bgcolor"] .">" . "Hello " . $_GET["fname"] . " ". $_GET["lname"] . "!<br/>" . "Background color changed to the selected color";
}
else
{
  echo "<body bgcolor=". $default_color .">" . "Hello " . $_GET["fname"] . " ". $_GET["lname"] . "!<br/>" . "Background color changed to the default color";
}
于 2013-02-25T09:15:49.310 回答
0

使用这样的东西

 <input type="hidden" value="your-color" name="bgcolor"/>

       if($_GET["bgcolor"] == 'color'){
        $color = 'color'
        }else {
        $color = 'other color'
        }
    echo '<body bgcolor='.$color.'>';
于 2013-02-25T09:08:33.197 回答
0

假设每种可用颜色都有一个单选按钮,您可以通过将颜色保存在单选按钮的 value 属性中来做到这一点。该值将在 POST 上传递。

<input type="radio" value="red" name="bgcolor"/>

结果是

$_POST["bgcolor"] === "red"
于 2013-02-25T09:09:26.093 回答