Jump to content

Recommended Posts

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']);
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/52057-problem-with-opera-script-wont-run/
Share on other sites

 

 

<?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']);
}
?>

 

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?

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.

  • 2 weeks later...

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.