SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    totally funky implode problem.

    Ok... here I really can't figure out what is going wrong. Really not.

    Here is a line of a form within a loop:
    PHP Code:
    <input type="checkbox" name="textID[]" id="textID" value="<?=$row['textID']?>" />
    and here is the kind of output:
    PHP Code:
    <input type="checkbox" name="textID[]" id="textID" value="2" />
    <
    input type="checkbox" name="textID[]" id="textID" value="3" />
    <
    input type="checkbox" name="textID[]" id="textID" value="4" />
    <
    input type="checkbox" name="textID[]" id="textID" value="5" /> 
    now here is how I try to delete the selected rows:
    PHP Code:
    $textID implode", "$_POST["textID"] );

    $sql
    "DELETE FROM userstexts 
    WHERE textID IN ("
    $textID ")"

    $db->query($sql); 
    And I get a

    Warning: Bad arguments to implode()

    message.

    It seems that I have done it like that for weeks and, here, it suddenly doesn't work.

    I really can't spot my mistake so I need your help.

    thanks in advance.

  2. #2
    Non-Member
    Join Date
    Jan 2004
    Location
    Planet Earth
    Posts
    1,764
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Whenever I verify if a CHECKBOX has been selected or not, I get 'on' if it has been selected ?

    If a CHECKBOX hasn't been selected, then it's field name you give it, is not SET

    This totally confused me as well when learning PHP to begin with, so you need to verify that a CHECKBOX has been selected, if not, then create the required variable with 0 - note an INTEGER, and not a BOOLEAN ?

    If you use a BOOLEAN, then this apparently makes no difference either I noticed this in fact the other day there when I was putting together some form validation classes I'm working on just now

    Hope this helps anyways, good luck.

  3. #3
    ********* Wizard silver trophy Cam's Avatar
    Join Date
    Aug 2002
    Location
    Burpengary, Australia
    Posts
    4,495
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    I'd just do it like this
    PHP Code:
      funtion implode_checkbox $name ) {
          if ( !
    is_array($_POST[$name]) ) {
             
    trigger_error('Invalid arguments passed to <strong>implode_checkbox()</strong>');
          }
      
          
    $ret '';
          foreach ( 
    $_POST[$name] as $chk => $v ) {
              if ( isset(
    $v) ) {
                  
    $ret .= "{$chk}, ";
              }
          }
          
    $ret substr($ret0strlen($ret) - 2);
      
          return 
    $ret;
      } 
    Just wrote that then and I haven't played with checkboxes for a while but it should work or at least be close

  4. #4
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks a lot cam

    I will give it a try for sure. thumbs up

  5. #5
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok I have discovered that my problem was not directly related to the code posted above. I thought I was going insane. Everything was ok and all of a sudden, everything went wrong. This is rather an array_map/stripslashes if gpc is on that is the cause of my problem. For the follow up, I have opened a thread dedicated to this problem right here:

    http://www.sitepoint.com/forums/showthread.php?t=172338


  6. #6
    SitePoint Zealot
    Join Date
    Mar 2004
    Location
    New Jersey
    Posts
    140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    By the way, DJ P@CkMaN:
    PHP Code:
     $ret substr($ret0strlen($ret) - 2);

      
    # is the same as
      
    $ret substr($ret0, -2); 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •