Multiple Delete Buttons

HI,

I have this code:

[php]<?php
ini_set(‘display_errors’,1);
error_reporting(E_ALL);
require_once("…/.common/.init.php");
$style = ‘…/.common/default.css’;

try {
$db = new PDO(DBASE);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo $e->getMessage();
die();
}

?>

Test <? $table = 'AanbodSpul'; $query = $db->query("SELECT * FROM $table ORDER BY id DESC");

function Delete($id) {
global $table;
global $db;

echo "This is a test: $id";

}

$i = -1;

while($result = $query->fetch(PDO::FETCH_OBJ)) {
$id = $result->id;
$lidnr = $result->lidnr;
$datum = $result->datum;
$omschrijving = $result->tekst;

$i++;

$plaatje="../fotoos/".$id.".jpg";
$ext = "jpg";
	
if (!is_file($plaatje)) 
	{$plaatje='../fotoos/blanco.gif'; $ext = "gif";}
	
	$src="resizefoto.php?plaatje=$plaatje&ext=$ext";
	$info = "Spullen:$id <small>$datum</small>";
					
	if(isset($_POST['delete'][$i]))
		Delete($id);

?>

<img id=‘foto’; src=’<? echo $src; ?>’;>
<? echo $info;?>
<? echo $omschrijving;?>
<input type='submit' id='delete' name='delete[]' value='Delete' title='wis advertentie'></td>
<? } ?>
[/php]

I’m trying to check which delete button is clicked. But whatever button I click only the $id of the first button is shown. What am I doing wrong ?

I solved my problem by doing this:

<input type='submit' id='delete' name='delete<? echo $i; ?>' value='Delete' title='wis advertentie'>

and:

[php]if(isset($_POST[‘delete’.$i]))
Delete($id);[/php]

But I have another problem:

If I do the delete query:

[php]function Delete($id) {
global $db, $table;

$query = $db->query("DELETE FROM $table WHERE id = $id");
if($query) echo "ID: $id verwijderd";
if (is_file("../fotoos/$id.jpg")) 
unlink("../fotoos/$id.jpg");

}[/php]

after the select query:

[php]$query = $db->query(“SELECT * FROM $table ORDER BY id DESC”);[/php]

then after submiting I have also to refresh the page to completley remove it from showing.

But if I place the delete query before the select query everything is directly removed without refreshing the page again.

Does somebody know what the cause of this problem is?

Now I have a while loop to display the data and delete button and another loop to check which button was set. Now everything is removed completely.

I was wondering if this is the right way ??

anybody ?

Sponsor our Newsletter | Privacy Policy | Terms of Service