0

I have a webpage that gets input from the user with a form. after the user enters their input and picks a specific day in which the input should go under and clicks on the submit button I want to add their input into the table below. can someone show me how I can do this using PHP thank you. below is my code

<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>

below is the css file for the webpage

 .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;
}
4
  • 1
    Have you tried anything so far? Commented Dec 2, 2019 at 3:05
  • Do you need it dynamically or statically Commented Dec 2, 2019 at 3:07
  • statically for now @vivekmodi Commented Dec 2, 2019 at 3:09
  • Welcome to SO! In order to post a question you should bring a minimum information as a input sample and expected output sample (if needed), what did you try and your research, in order to show some effort, as SO is not a free coding service. What did you try? Commented Dec 2, 2019 at 3:44

1 Answer 1

1

Simply use some php conditions and all like

    <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>

Make your form method post and if you are using get then use $_GET instead of $_POST

Sign up to request clarification or add additional context in comments.

7 Comments

hey, I tried this but it is not adding it to the table. the table just has '-' it will not update can you help
Have you submitted the form
yeah when i hit the Add Recipe button nothing changes
hey it works but every time i click add recipe the previous one disappears is there anyway to stop that
If you will use dynamic than it will be easy to keep this information
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.