我试图获得在无线电中选择的值作为我的结果页面的背景颜色。
HTML代码:<form action="PhotoForm.php" method="post" enctype="multipart/form-data">
<input type="radio" name="Colour" value="Pink"/> Pink
<input type="radio" name="Colour" value="Blue"/> Blue
<input type="radio" name="Colour" value="Green"/> Green
<input type="radio" name="Colour" value="Grey"/> Grey
<input type="reset" value="Reset">
<input type="submit" value="Upload Images" name="submit">
</form>
PHP代码:$Color = "white";
$Selection = $_POST["Colour"];
if($Selection == "Pink"){
$Color = "pink";
}elseif($Selection == "Blue"){
$Color = "blue";
}elseif($Selection == "Green"){
$Color = "green";
}elseif($Selection == "Grey"){
$Color = "SlateGrey";
}
我目前得到的错误显示为:
注意:未定义索引:color在(php文件目录)第4行
我有问题弄清楚为什么它显示这个错误。任何帮助都将非常感激。
这可能会有帮助
<?php
// key is a color the user may submit, value is the color useful to this program
$validColors = array(
"pink" => "pink",
"blue" => "blue",
"green" => "green",
"grey" => "SlateGrey",
);
// form has been posted
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
// have an acceptable color
if (isset($_POST['Colour']) && isset($validColors[strtolower($_POST['Colour'])]) {
$color = $validColors[strtolower($_POST['Colour'])];
}
// no valid color provided
else {
}
}