I have a table that generates a number of rows according to how many rows are in the database, but the submit button is only taking the last row in the table and not the one I selected. Any ideas of what I am doing wrong?
<?php
$result = mysql_query("SELECT * FROM booking");
while($row = mysql_fetch_array($result))
{
?>
<form class='table-form' id='form' method='post'>
<tr>
<input id="bookid" type="hidden" name="bookid" value="<?php echo ($row['booking_id']); ?>" />
<td>
<input id="bookingid"<?php echo ($row['booking_id']);?>
</td>
<td>
<?php echo ($row['user_id']); ?>
</td>
<td>
<?php echo ($row['event_id']); ?>
</td>
<td>
<?php echo ($row['payment_type']); ?>
</td>
<td>
<?php echo ($row['booking_date']); ?>
</td>
<td>
<button id="cancel" name="cancel" type="submit">Cancel</button>
</td>
</tr>
<?php
}
?>
</form>
</table>
</div>
<?php
if (isset($_POST['bookid'])){
$bookid = ($_POST['bookid']);
$result = mysql_query("DELETE FROM booking
WHERE booking_id = '$bookid'");
}
?>
while?foreach? where is the rest of your code?asdf'; DROP TABLE booking --'as the value for the bookid field using a hijacked version of your form?