用户使用PHP定义背景颜色

时间:2015-04-10 00:50:30

标签: php css html-table background-color

我试图弄清楚如何使用PHP更改表格的背景颜色。我知道我在某个地方有价值但我无法弄清楚在哪里。我认为我正处于正确的状态,我只是在某些地方遗漏了一些东西。任何帮助将不胜感激。

背景颜色:

    <form action= "post3.php" method="post">
    Author * : <input type="text" name="author"><br/>
    Email : <input type="text" name="email"><br/>
    Title * : <input type="text" name="title"><br/>

    Background color:
     <Input type = 'Radio' Name ='bgcolor' value= 'blue'
         <?PHP print $blue_status; ?>
         >Blue
     <Input type = 'Radio' Name ='bgcolor' value= 'red'
         <?PHP print $red_status; ?>
         >Red
    <P>

    Tag:
    <input type="checkbox" name="tag[]" value="General Interests"> General Interests
    <input type="checkbox" name="tag[]" value="Local Schools"> Local Schools
    <input type="checkbox" name="tag[]" value="Safety"> Safety
    <br/>

    <select name="City" id="City">
        <option value="0" selected="selected">Select any City</option>
        <option value="Arlington">Arlington</option>
        <option value="Dallas">Dallas</option>
        <option value="Ft. Worth">Fort Worth</option>
    </select>
    <br>
    Comment * : <br/><textarea name="comment" rows="5" cols="40"></textarea><br>
    <input type="Submit" name="SubmitThis" value="Preview">
  </form>

PHP:

$blue_status = 'unchecked';
    $red_status = 'unchecked';

    if (isset($_POST['SubmitThis'])) {

        $selected_radio = $_POST['bgcolor'];

        if ($selected_radio == 'blue') {

            $blue_status = 'bluebg';

        }
        else if ($selected_radio == 'red') {

            $red_status = 'redbg';

        }

    }

表格:

  $output = "<table border=\"1\" style=\"width:30%\">
  <tr>
    <td>Author:</td>
    <td>$author</td>
  </tr>
  <tr>
    <td>Title:</td>
    <td>$title</td>
  </tr>
  <tr>
    <td>Tag:</td>
    <td>$tagStr</td>
  </tr>
  <tr>
    <td>City:</td>
    <td>$cities</td>
  </tr>
    <tr>
    <td>Comment:</td>
    <td>$comment</td>
  </tr>

  </table>
";

CSS:

.redbg{
    background-color: indianred;
}
.bluebg{
    background-color: lightblue;
}

0 个答案:

没有答案