From: "Tyler Longren" <[EMAIL PROTECTED]>
> That's not the exact code. The exact code is below. Multiple workers
> are being selected from a MULTIPLE <select> form field. I just use a
> while loop do go through the selected ones to delete them individually.
>
> PHP Version: 4.3.4
> MySQL Version: 4.0.17
>
> $i="0";
Don't put quotes around numbers. $i = 0; is all you need.
> while ($i <= "$selected") {
You also don't need quotes around just a variable. ($i <= $selected) is all
you need.
> $delete_assignment = mysql_query("DELETE FROM webprojectassign WHERE
> workerid='$assigned[$i]'");
> $i++;
> }
> if (mysql_affected_rows($delete_assignment) < "1") {
> $tpl->newBlock('message');
> $tpl->assign("message","<b>ERROR:</b> There was an error deleting those
> workers from the project.");
> }
> else {
> $tpl->newBlock('message');
> $tpl->assign("message","The workers have been deleted from the
> project.");
> }
The problem you're having is that your IF check of mysql_affected_rows() is
outside of your WHILE loop. So, you're executing a series of DELETE queries,
yet only checking mysql_affected_rows() for the very last one (which
evidently does not actually delete anything).
You could probably benifit from a "DELETE FROM webprojectassign WHERE
worderid IN (1,2,3,45)" syntax, too, so you only need to do a single query.
Since it's coming from a MULTIPLE <select>, a simple
$list = implode(',',$_POST['select_name']);
will create the list. Although you'd be better off looping through each one
making sure it's a number, though, to prevent any SQL injection attacks.
Ask if you need anymore info. :)
---John Holmes...
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php