switch 函数变量不显示

发布于 2024-10-14 18:22:26 字数 645 浏览 3 评论 0原文

我有这个开关函数,它应该获取查询字符串中传递的参数的值,并根据它决定变量的值:

<?php

switch($_REQUEST['textcolor']){
case "white":
$textcolor = $white;
break;
case "black":
$textcolor = $black;
break;
}

?>

$_REQUEST 从以下链接获取它的值:

 <a href="index2.php?status=Busy&codigo2=<?php echo $codigo2; ?>&textcolor=white">

这是我有一个隐藏元素的形​​式,它应该显示值,但没有:

 <form>
            <input type="hidden" value="<?= $textcolor ?>">
        </form>

任何想法为什么 $textcolor 变量不显示?

编辑:已解决,原因确实是未声明变量。谢谢!

I've got this switch function that is suppose to get the value of a parameter passed in a query string, and upon it decide the value of the variable:

<?php

switch($_REQUEST['textcolor']){
case "white":
$textcolor = $white;
break;
case "black":
$textcolor = $black;
break;
}

?>

The $_REQUEST gets it's value from this link:

 <a href="index2.php?status=Busy&codigo2=<?php echo $codigo2; ?>&textcolor=white">

and this is the form in which I have a hidden element that;s suppose to show the value, but does not:

 <form>
            <input type="hidden" value="<?= $textcolor ?>">
        </form>

Any ideas why the $textcolor variable is not showing?

EDIT: Solved, the reason was indeed variable not declared. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里兽 2024-10-21 18:22:26
switch($_REQUEST['textcolor']){
    case "white":
        $textcolor = $white;
        break;
    case "black":
        $textcolor = $black;
        break;
}

$white 和 $black 是在哪里定义的?

编辑

做:

$white = 'white';
$black = 'black';

switch($_REQUEST['textcolor']){
    case "white":
        $textcolor = $white;
        break;
    case "black":
        $textcolor = $black;
        break;
}

看看会发生什么

switch($_REQUEST['textcolor']){
    case "white":
        $textcolor = $white;
        break;
    case "black":
        $textcolor = $black;
        break;
}

Where are $white and $black defined?

EDIT

Do:

$white = 'white';
$black = 'black';

switch($_REQUEST['textcolor']){
    case "white":
        $textcolor = $white;
        break;
    case "black":
        $textcolor = $black;
        break;
}

and see what happens

人事已非 2024-10-21 18:22:26

switch 中添加最后一个 case

default:
   die('textcolor is not '.$black.' or '.$white);
break;

Add a last case in the switch

default:
   die('textcolor is not '.$black.' or '.$white);
break;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文