delete function


#1

hi guyz…i was stuck with my project for past few days because my delete function not working…now it working but not accurate…if i use…
[php]
<?php
$sql = “select *from details”;
$query = @mysql_query($sql);
$countData = @mysql_num_rows($query);
?>

<?php while ($nt=mysql_fetch_array($query))
{
echo "delete
";
}?> <?php if (isset($_REQUEST['delete'])) $select ="DELETE from details where amount = '$nt[amount]'"; $querys = @mysql_query($select); $countDatas = @mysql_num_rows($querys); ?>

[/php]…it doest work…if i took out the isset($_REQUEST(delete))…its working…but delete the data directly even i didnt hit the delete button…
[php]
<?php
$sql = “select *from details”;
$query = @mysql_query($sql);
$countData = @mysql_num_rows($query);
?>

<?php while ($nt=mysql_fetch_array($query))
{
echo "delete
";
}?> <?php //if (isset($_REQUEST['delete'])) $select ="DELETE from details where amount = '$nt[amount]'"; $querys = @mysql_query($select); $countDatas = @mysql_num_rows($querys); ?>

[/php]…please help…im realy have no idea…and my project getting very late…thanks in advanced


#2

I’ve seen you requesting stuff like this a few times now, and from what I’ve seen, I’m thinking you’re taking a completely wrong approach on this. Here’s what I’m thinking you’re trying to do:

You have a page with a list of items, extracted from a database. Each of those list entries has a link named ‘Delete’, which functions as a way to actually delete this entry from the database, correct?

Question: how do you define WHICH ‘Delete’ link was clicked, i.e. which entry should be deleted? Each of the links has identical href, name and id attributes (and id attributes should have unique values throughout the document).

Since the page will reload after clicking either of them, the SELECT statement is being run again, and the only thing you’ll be deleting, is the last entry that was extracted (and even that you won’t see until the next pageload, because the entry is being extracted before it is being deleted).