Reputation: 128
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;
}
Upvotes: 0
Views: 38
Reputation: 812
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
Upvotes: 1