Browser problem or code problem?
Date: 01/17/06
(PHP Community) Keywords: php, mysql, browser, database, sql
Ok, so I have the following code, meant to delete a category in a script I'm working on. It takes the category ID from the $_GET array, checks the database to make sure such a category ID exists, then deletes it if true or shows an error if false.
if ($_GET['categories'] == "deletecat") {
if (isset($_GET['delid'])) {
$idofd = cleaninput($_GET['delid'], 1);
$idofd = (int)$idofd;
$check_delete = mysql_fetch_assoc(mysql_query("SELECT * FROM table_cats WHERE cat_id = '" . $idofd . "' LIMIT 1", $connect));
if (empty($check_delete)) {
echo "Error: There is no category with the ID number " . $idofd . ".
";
}
else {
$deletecateg = mysql_query("DELETE FROM table_cats WHERE cat_id = '" . $idofd . "' LIMIT 1", $connect);
if ($deletecateg) {
echo "The category was successfully deleted.
Go back
";
}
else {
echo "The category could not be deleted: " . mysql_error($connect) . "
";
}
}
}
else {
echo "Error: No category selected for deletion.
";
}
}
When I execute this code, Firefox will always tell me that there is no category with the ID number specified, even when it does exist - however it will delete the category anyway. Opera does things correctly - a category is selected for deletion and the success message is shown.
Is this a browser problem or a code problem? I have tried all sorts of different solutions, originally the code was as such:
if (!empty($check_delete)) {
// delete the category
}
else {
// display error
}
However I switched it around thinking that maybe Firefox was taking too long to check the category and then finding it deleted or something like that.
I haven't been able to test this in IE yet, but I have a feeling it might work, like it did in Opera. So... any ideas as to why it's not working in Firefox?
Specs: PHP 5.0.5/MySQL 5.0.15 running on Windows XP (local testing server); Firefox 1.5
Thanks in advance.
PS: First post to this community! *Bows low*
Edit: Solved! Firefox didn't like having a button in the form field used to get the delete ID (it's a "get" method form). Changed it to a normal link and everything now seems to be working as it should. :)
Source: http://www.livejournal.com/community/php/396330.html