Hi there,
Pretty new to PHP and having a problem when deleting data from my MySQL Table after populating it into a listbox, seletcing it and using a button to delete the selected row.
Heres the code:
<?php
//create and execute query
$query = 'SELECT product_ID FROM products ORDER BY product_ID';
$result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
//create selection list
echo "<select name='products'>\n";
echo "<option value='Select event'>Select an event to be edited\n";
while($row = mysql_fetch_row($result))
{
$eventSelect = $row[0];
$eventid = $row[1]; //set this to the column of the primary key
echo "<option value='$eventid'>$eventSelect</option>\n";
}
echo "</select>"
?>
<input name="delete" type="submit" class="submitForm" value="Delete" id="delete">
</td>
<?php
// Delete event data
if ($_REQUEST['delete']){
//define variables
$eventSelect = $_POST['eventSelect'];
echo $eventSelect;
//create and execute query
$query = "DELETE FROM products WHERE product_ID = '$eventSelect' LIMIT 1";
$result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
}
?>
Any Suggestions?.
Thanks