-1

I am trying to submit this form but it only submits the hidden input field. I can't understand why. It was working before.

while ($row = mysqli_fetch_array($gettimesheets)) {
    $date = $row['Date'];
    $date = date('d-m-Y', strtotime($date));
    $teachername = $row['StaffName'];
    $teacherid = $row['StaffID'];
    $starttime = $row['StartTime'];
    $endtime = $row['EndTime'];
    $totalhours = $row['TotalHours'];
    $timesheetid = $row['id'];

    ?>
    <tr>
        <form action="edittimesheet.php" method="post">
            <td class="text-center"><?php echo $date; ?></td>
            <td><?php echo $teachername; ?></td>
            <td><?php echo $teacherid; ?></td>
            <td><input type="time" name="starttime" class="form-control" value="<?php echo $starttime; ?>"></td>
            <td><input type="time" name="endtime" class="form-control" value="<?php echo $endtime; ?>">
                <input type="text" name="timesheetid" value="<?php echo $timesheetid; ?>" hidden></td>
            <td class="text-right">
                <input type="submit" class="btn btn-success" value="Edit"/>
                <a href="deletetimesheet.php?id=<?php echo $timesheetid; ?>"
                   class="btn btn-simple btn-danger">Delete</a>
            </td>
        </form>
    </tr>

    <?php
}
Moshiur
  • 537
  • 5
  • 14
Esa Ali
  • 9
  • 3

2 Answers2

1

It's odd but putting parts of a table inside a form is not a good idea. Actually browsers in such situation are confused! You can put your whole form inside a cell (td).

For more information Check this

0

Make your form outside your table and on your edit-submit button the id you edit.

<form action="edittimesheet.php"     
<table>
<?php 
while ($row = mysqli_fetch_array($gettimesheets)) {
     $date = $row['Date'];
     $date = date('d-m-Y', strtotime($date));
     $teachername = $row['StaffName'];
     $teacherid = $row['StaffID'];
     $starttime = $row['StartTime'];
     $endtime = $row['EndTime'];
     $totalhours = $row['TotalHours'];
     $timesheetid = $row['id'];

                                                ?>
                                                <tr>
method="post">
                                                  <td class="text-center"><?php echo $date ;?></td>
                                                  <td><?php echo $teachername ;?></td>
                                                  <td><?php echo $teacherid ;?></td>
                                                  <td><input type="time" name="starttime[$timesheetid]" class="form-control" value="<?php echo $starttime; ?>" ></td>
                                                  <td><input type="time" name="endtime[$timesheetid]" class="form-control" value="<?php echo $endtime; ?>" >
                                                  <input type="text" name="timesheetid[$timesheetid]" value="<?php echo $timesheetid; ?>" hidden></td>
                                                  <td class="text-right">
                                                    <input type="submit" name="edit" value ="<?php echo $timesheetid; ?>;" class="btn btn-success" value="Edit"/>
                                                    <a href="deletetimesheet.php?id=<?php echo $timesheetid; ?>" class="btn btn-simple btn-danger">Delete</a>
                                                  </td>

                                                </tr>

                                                <?php
                                              }
?>
</table>
</form>
db1975
  • 755
  • 3
  • 9