根据 If 语句更改 <fieldset> 颜色

changing the <fieldset> colour dependant on an If statement

首先很抱歉,如果这是一个愚蠢的问题,但她会...... 我正在尝试根据这样的 $_session 变量创建颜色变化

<li>             
  <fieldset>
    <?php

    if ($_SESSION['Question1Answer'] != '1C') {
        <?php fieldset id="incorrect" />
        echo "Q1. When was barb wire patented.";
        echo "The Correct answer is 1874";
    }
        <?php fieldset id="correct" />
    ?>
  </fieldset>                   
</li>

然后在风格sheet我有

#incorrect {
    color: red;
    border: medium;
}
#correct {
    color: green;
    border: thin;
}

有谁知道我做错了什么吗?

您需要在输出 <fieldset> 之前检查答案是否正确,然后将 id 应用于该字段集:

<?php
if ($answer == "correct") {
  $fieldsetID = "correct";
} else {
  $fieldsetID = "incorrect";
}
?>
<li>
  <fieldset id="<?php echo $fieldsetID ?>">
  </fieldset>                   
</li>