Log in

View Full Version : Coding Problems


Kirk Y
05-30-2006, 12:50 AM
I've got messages being pulled from a database and I'm trying to create an option for the other administrators to remove the messages by clicking an image. I'm using the following code:

$blast_msg = $db->query_read("
SELECT *
FROM blastmsg
");
while ($blast = $db->fetch_array($blast_msg))
{
$user = $blast['user'];
$date = $blast['date'];
$message = $blast['message'];
$id = $blast['blastid'];
}
if ($_GET['do'] == 'delete')
{
if (!$blast = $db->query_first("SELECT blastid FROM blastmsg WHERE blastid = " . intval($_GET['id'])))
{
eval(standard_error(fetch_error('non_existant')));
}

$db->query("DELETE FROM blastmsg WHERE blastid = '$id'");
eval(print_standard_redirect('blast_del'));
}

The problem is that upon clicking the image, the wrong message is being erased.

I'm using this as the URL:
<a href='blast.php?{$vbulletin->session->vars['sessionurl']}do=delete&amp;id=$id'>

Thanks in advance for any ideas.

calorie
05-30-2006, 01:03 AM
Your delete query is using the last ID set from the while loop instead of something like the following:

$db->query("DELETE FROM blastmsg WHERE blastid = " . intval($blast['blastid']));

Kirk Y
05-30-2006, 05:02 AM
D'oh! Can't believe I missed that -- thanks Calorie.