I'm trying to make a log of cars going in and out of a parking lot.
The car info is retrieved from a database and is working fine. The problem I'm having is getting the in/out times to store into the database. In a previous page I had done it so that the form was separate from the table and the input info would be updated but for this page I need to have a dynamic amount of fields varying on the cars in the database. I am not sure what I am doing wrong but here is my code, the data is not being sent or stored in the data base.
<h3>Update Car</h3>
<form action="carLog.php" method="post">
<fieldset>
<legend>Car Log</legend>
<?php //This prints out the car log data
$sql = "SELECT * FROM carLog";
$result = $databaseConnection->query($sql);
echo "<table class='TFtable' border='1' style='width':100%>"; //starts the table tag
echo "<tr>
<td>Name</td>
<td>Vehicle</td>
<td>Licence Plate</td>
<td>In</td>
<td>Out</td>
<td>In</td>
<td>Out</td>
<td>Comments</td>
</tr>"; //sets headings
while($row = $result->fetch_assoc()) { //loops for each result
echo "<tr>
<td>".$row['name']."</td>
<td>".$row['vehicle']."</td>
<td>".$row['plate']. "</td>
<td><input type='text' size='5' maxlength='5' name='inTime' value='".$row['inTime']."' id='inTime' /></td>
<td><input type='text' name='outTime' value='".$row['outTime']."' id='outTime' /></td>
<td><input type='text' name='inTime2' value='".$row['inTime2']."' id='inTime2' /></td>
<td><input type='text' name='outTime2' value='".$row['outTime2']."' id='outTime2' /></td>
<td><input type='text' name='comments' value='".$row['comments']."' id='comments' /></td>
</tr>";
}
echo "</table>"; //closes the table
?>
<input type="submit" name="Save" value="Save" />
</fieldset>
</form>
The database connection is fine and working. Here is the php that handles the post:
if (isset($_POST['Save'])){
$name = $_POST['name'];
$vehicle = $_POST['car'];
$plate = $_POST['plate'];
$inTime = $_POST['inTime'];
$outTime = $_POST['outTime'];
$inTime2 = $_POST['inTime2'];
$outTime2 = $_POST['outTime2'];
$comments = $_POST['comments'];
$query = "UPDATE carLog SET inTime = '$inTime', outTime = '$outTime', inTime2 = '$inTime2', outTime2 = '$outTime2' WHERE plate = '$plate'";
$databaseConnection->query($query);