tjodolv Posted May 18, 2007 Share Posted May 18, 2007 Hi there. I have a script that retrieves data from a database, and lists it. Each entry in the list has a delete button, and when I press the button, the corresponding entry gets deleted. The list looks like this: EntryDelete Entry 1[X] Entry 2[X] Entry 3[X] Entry 4[X] Entry 5[X] Next to this table, there is an input field, with a "Save" button. When I type in en entry and press "Save", the entry is stored in the database, the script refreshes, and the entry is immediately displayed in the list. This all works fine in Firefox, IE and Safari, but in Opera I get a weird bug. If i add an entry, everything works fine, but if I try to delete an entry, nothing happens. Actually, specifically this happens: The script is just one part of a larger PHP file. The adress looks like ../admin.php?edit_inventory If add an entry by clicking "Save" (or deleting in any browser but Opera), I am returned to this adress with the changes displayed correctly. If I try to delete anything in Opera, I am returned to ../admin.php, and on further inspection, nothing has been deleted from the db. What is my problem? I figure it is something with Opera's handling of POSTDATA, but how do I fix it? The scripts: <?php // The list. Every item in the database is printed like this in a while {} loop // This page is accessed via ../admin.php?edit_inventory echo '<tr> <td>' . $row['entry'] . '</td> <td> <form action="update.php" method="post"> <input type="hidden" name="return" value="edit_inventory" /> <input type="hidden" name="table" value="inventory" /> <input type="hidden" name="id" value="' . $row['id'] . '" /> <input type="image" src="lib/img/delete.gif" name="delete" value="del_from_list" /> </form> </td> </tr>'; ?> <?php // This is the update.php if (isset($_POST['del_from_list'])) { $sql = "DELETE FROM " . mysql_escape_string($_POST['table']) . " WHERE id = " . (int)$_POST['id'] . ""; $del = mysql_query($sql, $connection); mysql_close($tilkobling); header("Location: admin.php?" . $_POST['return']); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52057-problem-with-opera-script-wont-run/ Share on other sites More sharing options...
calabiyau Posted May 18, 2007 Share Posted May 18, 2007 <?php // The list. Every item in the database is printed like this in a while {} loop // This page is accessed via ../admin.php?edit_inventory echo '<tr> <td>' . $row['entry'] . '</td> <td> <form action="update.php" method="post"> <input type="hidden" name="return" value="edit_inventory" /> <input type="hidden" name="table" value="inventory" /> <input type="hidden" name="id" value="' . $row['id'] . '" /> <input type="image" src="lib/img/delete.gif" name="delete" value="del_from_list" /> ///////the input type directly above here has a name of delete and a value of del_from_list //////when you check if it is set below you are checking $_POST['del_from_list'] when it should ////be $_POST['delete']. That is one problem anyway, though I can't figure out why this would work ////in any browser </form> </td> </tr>'; ?> <?php // This is the update.php if (isset($_POST['del_from_list'])) { $sql = "DELETE FROM " . mysql_escape_string($_POST['table']) . " WHERE id = " . (int)$_POST['id'] . ""; $del = mysql_query($sql, $connection); mysql_close($tilkobling); header("Location: admin.php?" . $_POST['return']); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/52057-problem-with-opera-script-wont-run/#findComment-256653 Share on other sites More sharing options...
tjodolv Posted May 18, 2007 Author Share Posted May 18, 2007 Yeah, that was a misspell. I keep all the variables and other names in Norwegian, it just slipped me when I translated. That's not the Issue. Quote Link to comment https://forums.phpfreaks.com/topic/52057-problem-with-opera-script-wont-run/#findComment-256664 Share on other sites More sharing options...
tjodolv Posted May 19, 2007 Author Share Posted May 19, 2007 bump..? Quote Link to comment https://forums.phpfreaks.com/topic/52057-problem-with-opera-script-wont-run/#findComment-257184 Share on other sites More sharing options...
AndyB Posted May 19, 2007 Share Posted May 19, 2007 if (isset($_POST['del_from_list'])) { Your form does not have an input named del_from_list, it's named delete. Quote Link to comment https://forums.phpfreaks.com/topic/52057-problem-with-opera-script-wont-run/#findComment-257236 Share on other sites More sharing options...
tjodolv Posted May 20, 2007 Author Share Posted May 20, 2007 Yeah, that was a misspell. I keep all the variables and other names in Norwegian, it just slipped me when I translated. That's not the Issue. Like i said in the first post, it works in FF and Safari, but not in Opera... I guess this is more of an Opera-related question, but is there a workaround? Quote Link to comment https://forums.phpfreaks.com/topic/52057-problem-with-opera-script-wont-run/#findComment-257285 Share on other sites More sharing options...
AndyB Posted May 20, 2007 Share Posted May 20, 2007 Like i said in the first post, it works in FF and Safari, but not in Opera... I guess this is more of an Opera-related question, but is there a workaround? But there still isn't any form field named del_from_list so how checking for it being set is useful escapes me. If it 'works' in FF and Safari then I doubt the code you posted is actually what you have running. Quote Link to comment https://forums.phpfreaks.com/topic/52057-problem-with-opera-script-wont-run/#findComment-257888 Share on other sites More sharing options...
tjodolv Posted May 31, 2007 Author Share Posted May 31, 2007 I figured it out (I think...): The problem was that my "Submit-button" was an image. For some reason, Opera and IE would not handle it correctly. I may have done something wrong, but anyways... This seems not to work in Opera or IE: <input type="image" src="lib/img/delete.gif" name="slett_listeinnhold" value="slett_listeinnhold" /> But this does: <input type="submit" name="slett_listeinnhold" value="X" /> Where the receiving script looks like this: <?php // ... elseif (isset($_POST['slett_listeinnhold'])) { $sql = "DELETE FROM " . mysql_escape_string($_POST['tabell']) . " WHERE id = " . (int)$_POST['id'] . ""; $slett = mysql_query($sql, $tilkobling); mysql_close($tilkobling); // går tilbake til lista header("Location: admin.php?" . $_POST['tilbake']); } // ... ?> So I did it like this: <?php // ... if (ereg("MSIE", $_SERVER['HTTP_USER_AGENT']) || ereg("Opera", $_SERVER['HTTP_USER_AGENT'])) { $slettListeinnhold = '<input type="submit" name="slett_listeinnhold" value="X" />'; } else { $slettListeinnhold = '<input type="image" src="lib/img/delete.gif" name="slett_listeinnhold" value="slett_listeinnhold" />'; } // ... $visning = sporring("*", "forstehjelp_tiltak", "", "tiltak"); $ant_rader = mysql_num_rows($visning); //skriver ut resultatet for($i = 0; $i < $ant_rader; $i++) { $rad = mysql_fetch_array($visning); if ($i % 2) { $radFarge = "mork"; } else { $radFarge = "lys"; } echo "\t\t\t\t\t" . '<tr class="' . $radFarge . '">' . "\n"; echo "\t\t\t\t\t\t" . '<td>' . $rad['tiltak'] . '</td>' . "\n"; echo "\t\t\t\t\t\t" . '<td> <form action="oppdater.php" method="post"> <input type="hidden" name="tilbake" value="adm_tiltak" /> <input type="hidden" name="tabell" value="forstehjelp_tiltak" /> <input type="hidden" name="id" value="' . $rad['id'] . '" /> ' . $slettListeinnhold . ' </form> </td>' . "\n"; echo "\t\t\t\t\t" . '</tr>' . "\n"; } // ... ?> I could, of course, just make it a button for all, but there is that thing called design, so... This is how I solved it. I appreciate any other suggestions Tested with success when Opera was identifying/masking itself as Firefox. Quote Link to comment https://forums.phpfreaks.com/topic/52057-problem-with-opera-script-wont-run/#findComment-265832 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.