I've an unusual problem. I have a script containing several checkboxes. These can obviously be selected at will by the user. When the user presses a button on the form, the script goes through the array of checkboxes and stores the 'checked' ones in a MySQL table.
It works fine except for one thing. The final checkbox entry is duplicated ... i.e. entered into the table twice. What makes things even more bizarre is that when I've tried to use a workaround that deletes the final entry, it actually deletes both the one I want to keep and the duplicate.😕
if (($Previous3) || ($Next3))
{
//Look for existing facilities attached to the property and delete any that exist first
//before adding any more.
$sql = "DELETE FROM temp_facilities WHERE property_id = $property_id";
$result = mysql_query($sql) or die ("Could not access temporary facilities database");
//Now copy the present settings over to the table.
if (isset($checkboxname))
{
foreach ($checkboxname as $value)
{
$sql = "INSERT INTO temp_facilities (facility_id,property_id)
VALUES ('$value','$property_id')";
//echo "sql = ".$sql;
$result = mysql_query($sql) or die ("Could not update facility/property link");
}
//Do some tidying up. For some reason, last checkbox is duplicated so we need to delete it.
//$row = mysql_insert_id();
//$sql = "DELETE FROM temp_facilities WHERE field_id = $row";
}
}
else
{
$sql = "SELECT property_type FROM temp_properties WHERE property_id = $property_id";
$result = mysql_query($sql) or die ("Could not access temporary properties database");
$row = mysql_fetch_array($result,MYSQL_NUM);
$property_type = $row[0];
}
Actually, the page has two buttons. The above script operates if either button is pressed.