PHP用表单添加和更新表

时间:2019-12-02 03:02:39

标签: php html

我有一个网页,可以从用户那里获取带有表单的输入。在用户输入他们的输入并选择输入应在其中的特定日期并单击“提交”按钮之后,我想将其输入添加到下表中。有人可以告诉我如何使用PHP做到这一点谢谢。下面是我的代码

<html>
<head>
    <title> Weekly Recipes </title>
    <link rel="stylesheet" type="text/css" href="weeklyCalendarRepstyles.css">

</head>
<body>

<div class="heading">
  <h2>Weekly Recipes</h2>
</div>

<form id="recipe-form">
  <input type="text" name="task" id="task" class="task_input">
  <select id="day">
    <option value="0">Sunday</option>
    <option value="1">Monday</option>
    <option value="2">Tuesday</option>
    <option value="3">Wednesday</option>
    <option value="4">Thursday</option>
    <option value="5">Friday</option>
    <option value="6">Saturday</option>
  </select>
  <button type="submit" class="task_btn" name="submit">Add Recipe</button>

</form>

<div>
  <table id="t01">
    <tr>
      <th>Sunday</th>
      <th>Monday</th>
      <th>Tuesday</th>
      <th>Wednesday</th>
      <th>Thursday</th>
      <th>Friday</th>
      <th>Saturday</th>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
      <td></td>
    </tr>
  </table>
</div>

</body>

<script> </script>
</html>

下面是网页的CSS文件

 .heading {
  width: 400px;
  margin: 30px auto;
  text-align: center;
  color: #6B8E23;
  background: #FFF8DC;
  border: 2px solid #6B8E23;
  border-radius: 20px
}

form {
  width: 320px;
  margin: 30px auto;
  border-radius: 5px;
  padding: 10px;
  background: #FFF8DC;
  border: 1px solid #6B8E23;
}

table {
  width: 100%;
}

table,
th,
td {
  border: 1px solid black;
  border-collapse: collapse;
}

th,
td {
  padding: 15px;
  text-align: left;
}

table#t01 tr:nth-child(even) {
  background-color: #eee;
}

table#t01 tr:nth-child(odd) {
  background-color: #fff;
}

table#t01 th {
  background-color: #6B8E23;
  color: white;
}

1 个答案:

答案 0 :(得分:1)

只需使用一些php条件,就可以使用

    <tr>
    <td><?php if(isset($_POST['day']) && $_POST['day']==0){echo $_POST['task'];;}else{ echo "-";} ?></td>
    <td><?php if(isset($_POST['day']) && $_POST['day']==1){echo $_POST['task'];;}else{ echo "-";} ?></td>
    <td><?php if(isset($_POST['day']) && $_POST['day']==2){echo $_POST['task'];;}else{ echo "-";} ?></td>
    <td><?php if(isset($_POST['day']) && $_POST['day']==3){echo $_POST['task'];;}else{ echo "-";} ?></td>
    <td><?php if(isset($_POST['day']) && $_POST['day']==4){echo $_POST['task'];;}else{ echo "-";} ?></td>
    <td><?php if(isset($_POST['day']) && $_POST['day']==5){echo $_POST['task'];;}else{ echo "-";} ?></td>
    <td><?php if(isset($_POST['day']) && $_POST['day']==6){echo $_POST['task'];;}else{ echo "-";} ?></td>
  </tr>

发布您的表单方法,如果您使用的是get,请使用$ _GET代替$ _POST