Page 1 of 1

Gah! having problems passing array through form

Posted: Fri Jan 09, 2009 4:41 pm
by logik
Ok, I need to pass an array through a form. Take the code, loop through it and take the value of each element and use that to make a db query. The problem is what get's passed is "Array" and when i loop through, no matter how many checkboxes i check it only goes only and returns "A" instead of lets say "12"

here is an except from the form:

Code: Select all

while ($mail = mysql_fetch_array($query)) {
    echo '<tr class="mailbody">'
        ,  '<td width=5><input type="checkbox" name="deleWhatId[]" value="'.$mail[id].'"></td>';
}
here is where it should delete...:

Code: Select all

 
  $_POST[deleWhatId][0] = $_POST[deleWhatId][0] == '' ? $_POST[deleWhatId] : $_POST[deleWhatId][0];
  $countwhat = count($_POST['deleWhatId']);
  //if there are actually some elements checked
  if ($countwhat) {
    //loops through all elements and deletes if that mail belongs to this person BASTARDS try to <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> with it huh?
    for($i=0; $i<$countwhat; $i++) {
      $findMail = mysql_query("SELECT fid, uid FROM mail WHERE id='$_POST['deleWhatId'][$i]'");
      $mail      = mysql_fetch_array($findMail);
      if (($_POST[act1] == 'itwassent' || $_GET[act1] == 'itwassent') && $mail[fid] == $user[id]) {
        mysql_query("UPDATE mail SET wher='2' WHERE id='$_POST['deleWhatId'][$i]'");
        $whereFrom = 'Sent Folder';
      } elseif ($mail[uid] == $user[id]) {
        mysql_query("DELETE FROM mail WHERE uid='$user[id]' AND id='$_POST['deleWhatId'][$i]'");
        $whereFrom = 'Inbox';
      } else {
        $errorMsg = 'There was an error processing your request, the mail did not belong to you.<BR>';
      }
    }
    if ($errorMsg) {
      echo '<font color=red>',$errorMsg,'</font>';
    } else {
      echo '<center><font color=green>You have deleted ',nFormat($i),' piece(s) of mail from your ',$whereFrom,'<BR><BR></font></center>';
    }
  }
 
why is it returning the values A R R A Y and not the actual id? I NEVER HAD this problem before, this code worked on the old server I had, with an older version of php so I am thinking it must be something in the php.ini that needs to be changed. Can anyone please help?

Re: Gah! having problems passing array through form

Posted: Fri Jan 09, 2009 6:28 pm
by it2051229
Did you make the code?
since you have multiple checkboxes, all check boxes's values(which are the IDs) are arranged in an array when submitted.
Regarding your code, I don't see anything wrong with it, I created a test database here in my machine and it works
perfectly fine.

now the problem of "A" is what makes it interesting. try printing out the ID value of each checkbox like

Code: Select all

 
while ($mail = mysql_fetch_array($query)) {
    echo '<tr class="mailbody">'
        ,  '<td width=5><input type="checkbox" name="deleWhatId[]" value="'.$mail[id].'"> $mail[id] </td>';
}
 
and check if ALL what are printed is "A".

Re: Gah! having problems passing array through form

Posted: Fri Jan 09, 2009 6:46 pm
by logik
i have viewed the source and done that, and no the proper row value is the value of the checkbox...

yes i didn't write the script myself no idea why the hell it won't work it just passes the value "A R R A Y" a being [0] R being [1] and so on but like i said no matter how many are checked it only loops once and count() only returns 1

...like i said it worked with my old host, but since i got a new one it no longer works properly

Re: Gah! having problems passing array through form

Posted: Sat Jan 10, 2009 6:45 pm
by it2051229
where's your form tag?