I have created a support form for some clients, they submit information to it and I see it in a panel I have created. In this panel I want to have the ability to check a box next to a record and hit an update button and it will update that record with a time stamp showing I have completed the work and what time. Here is the sample code
echo "<table border='1'>
<tr>
<th>ICL</th>
<th>PAGE ID</th>
<th>SUBMISSION NAME</th>
<th>UPTDATES/BUGS</th>
<th>MISSING INFO</th>
<th>TIME OF SUBMISSION</th>
<th>COMPLETED</th>
<th>TIME COMPLETED</th>
</tr>";
echo "<form name='completed' action='insert4panel.php' method='post'>";
while($row = mysql_fetch_array($results))
{
echo "<tr>";
echo "<td>" . $row['ICL'] . "</td>";
echo "<td>" . $row['officename'] . "</td>";
echo "<td>" . $row['submitname'] . "</td>";
echo "<td>" . $row['feedback'] . "</td>";
echo "<td>" . $row['missinginfo'] . "</td>";
echo "<td>" . $row['TimeStamp'] . "</td>";
echo "<td><input type='checkbox' name='complete'></td>";
echo "<td>" . $row['completionstamp'] . "</td>";
echo "</tr>";
}
echo "<input type='submit' value='Update'>";
echo "</form>";
echo "</table>";
What happens when I hit submit I send it to this code
$timeissued=$_POST["complete"];
$date = date("m-d-y H:i:s");
mysql_query("INSERT INTO SITES (completed, completetime )
VALUES ('$timeissued' ,'$date')");
I know that I’m not telling it which record I want to add the timestamp or the check box to, so it isn’t going to do it, however it creates a new record with a timestamp doesn’t save the check box and leaves the rest of the fields blank. I’m sure the answer is simple
Modify your checkbox so that it is a
value=1attribute.Change the name of said checkbox to
name=complete[$id]Now, on the PHP side of things, do something along the lines of…
This will loop through ALL of the checkboxes you hit and set the
completedfield in your database to 1, and thecompletedtimefield to the current time stamp, which is an integer.Though, you shouldn’t be using mysql_* functions on account of them being deprecated. You should look into PDO.