PDA

View Full Version : IDs Over 10 Being Split



Titan85
12-12-2007, 05:46 PM
I have made a delete script with multiple delete. Everything runs great until the delete ID being fed hits 10 or more, then it splits it into 1 and 0 instead of 10. Here is the delete PHP:
###### If Delete Was Hit ######
else if ($_POST['delete']) {
$links = mysql_query("SELECT * FROM `cms_nav` ORDER BY id ASC") or die ("Error Getting Links! \n <br /> \n" .mysql_error());
$chk = mysql_num_rows($links);
for ($i=0; $i<$chk; $i++) {
$del_id = $checkbox[$i];
$del = mysql_query("DELETE FROM `cms_nav` WHERE id = '$del_id'") or die ("Error Deleting Selected! \n<br />\n" .mysql_error());
echo('Del ID: '.$del_id.' ');
}
echo('<meta http-equiv="refresh" content="2;URL=nav.php" /> <div class="message">The selected links have been deleted</div>');
}
###### ################# ######When I this code added to the script and the ID to be deleted is 10, it echos Del ID: 1 Del ID: 0

echo('Del ID: '.$del_id.' ');
Here is the HTML sending the information:

<input type="checkbox" name="checkbox" value="<?php echo $l['id']; ?>" />Anyone know why it is doing this?

Thanks in advance

Twey
12-13-2007, 04:38 AM
It isn't an array. You're looping over the characters of the string here:
for ($i=0; $i<$chk; $i++) {
$del_id = $checkbox[$i];In PHP, if you want an array from POST data the element names have to end with [].

Titan85
12-13-2007, 12:07 PM
It isn't an array. You're looping over the characters of the string here:
for ($i=0; $i<$chk; $i++) {
$del_id = $checkbox[$i];In PHP, if you want an array from POST data the element names have to end with [].So the code should be

<input type="checkbox" name="checkbox[]" value="<?php echo $l['id']; ?>" /> or do you mean:

$del_id = $checkbox[$i][];
Thanks

Twey
12-13-2007, 12:22 PM
<input type="checkbox" name="checkbox[]" value="<?php echo $l['id']; ?>">Don't use XHTML on the web right now: http://www.webdevout.net/articles/beware-of-xhtml