我如何从无线电输入中获得答案?

时间:2016-10-28 08:59:17

标签: php html

首先,我是PHP的新手,之前只做了一些HTML / CSS,所以我对这些东西知之甚少。

我在学校接受了一项任务;创建使用的东西:

  1. 回声
  2. HTML和PHP的组合
  3. PHP中的变量
  4. 输入
  5. 我一直试图制作的是一个页面,您可以在其中选择今天的哪一天,按OK,然后会显示一条消息:“今天是$今天。因此,星期五之前有X天。” / p>

    到目前为止我做了什么:

        <p>
            Temporary description with HTML <?php echo "<p> and PHP. </p>" ?>
        </p>
    
        <?php
    
    
            $ledestreng1;  
            $ledestreng2;  
            $ledestreng3;
    
            $ledestreng1 = "Today is ";  
            $ledestreng2 = " There is therefore ";
            $ledestreng3 = " days until friday."  
    
    
    
        ?>
    
    
    
        <form>
            <input type="radio" name="day" value="monday"> Monday<br>
            <input type="radio" name="day" value="tuesday"> Tuesday<br>
            <input type="radio" name="day" value="wednesday"> Wednesday<br>
            <input type="radio" name="day" value="thursday"> Thursday<br>
            <input type="radio" name="day" value="friday"> Friday<br>
            <input type="radio" name="day" value="saturday"> Saturday<br>
            <input type="radio" name="day" value="sunday"> Sunday<br>
            <input type="submit" name="submit" value="OK">
        </form>
    
        <?php
            if (isset($_POST[submit])){
            $today = $_POST[day];
            echo "<p>$ledestreng1 $today,$ledestreng2,$ledestreng3</p>";
            }     
          ?>
    

    我从这里做什么?如何从收音机输入中选出一天,如何知道星期五之前的剩余天数?我认为if语句会起作用,比如“如果”周四“被选中,那就是”3天“,直到星期五。”

    您对我如何做到这一点有什么建议吗?

1 个答案:

答案 0 :(得分:1)

HTML

<form method="POST">
    <input type="radio" name="day" value="monday"> Monday<br>
    <input type="radio" name="day" value="tuesday"> Tuesday<br>
    <input type="radio" name="day" value="wednesday"> Wednesday<br>
    <input type="radio" name="day" value="thursday"> Thursday<br>
    <input type="radio" name="day" value="friday"> Friday<br>
    <input type="radio" name="day" value="saturday"> Saturday<br>
    <input type="radio" name="day" value="sunday"> Sunday<br>
    <input type="submit" name="submit" value="OK">
</form>

PHP

<?php
if(isset($_POST['submit'])) {
    $day = $_POST['day'];

    if($day == "saturday") {
      echo "6 days untill it's friday";
    } elseif($day == "sunday") {
      echo "5 days untill it's friday";
    } elseif($day == "monday") {
      echo "4 days untill it's friday";
    } elseif($day == "tuesday") {
        echo "3 days untill it's friday";
    } elseif($day == "wednesday") {
        echo "2 days untill it's friday";
    } elseif($day == "thursday") {
        echo "1 days untill it's friday";
    } elseif($day == "friday") {
        echo "Today friday";
    }
}
?>