SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Colonel Jack O'neill Josh_'s Avatar
    Join Date
    Apr 2004
    Location
    NC
    Posts
    689
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP and checkboxes

    Hi, I'm trying to figure out how to get php to interact with checkboxes. What I'm trying to do is only update the fields where the checkbox is checked.
    here's some code
    PHP Code:
    <?php
    echo '<form>';
    echo 
    '<table border="1" width="100%" style="text-align:center;">';
    echo 
    '<tr><th>Game ID</th><th>BrokenLink #</th><th>Title</th><th>URL</th><th>Category ID</th><th>description</th><th>Fixed?</th></tr>';

    $sql "SELECT * FROM games WHERE brokenlink > 1 ORDER BY brokenlink";
    $query mysql_query($sql) or die(mysql_error());
    while(
    $row mysql_fetch_object($query)){
    $id $row->ID;
    $title $row->TITLE;
    $url $row->URL;
    $catid $row->CategoryID;
    $desc $row->description;
    $brokenlink $row->brokenlink;

    echo 
    '
    <tr><td>'
    .$id.'</td><td>'.$brokenlink.'</td>
    <td><input type="text" name="title" value="'
    .$title.'" maxlength="30" /></td><td><input type="text" name="url" value="'.$url.'" /></td>
    <td><input type="text" name="catid" value="'
    .$catid.'" maxlength="1" style="width:15px;" /></td><td><textarea name="desc" value="'.$desc.'"></textarea></td>
    <td><input type="checkbox" name="fix" /></td></tr>
    '
    ;
    }

    echo 
    '</table>';
    echo 
    '</form>';
    ?>
    My idea is to give the checkbox the same name as the ID. But the only problem I see with that is how do I get it to process the multiple checkboxes when it's submitted? Some kind of loop i guess...

  2. #2
    SitePoint Addict loadx's Avatar
    Join Date
    Jul 2004
    Location
    Melbourne, VIC, Australia
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    search the forums there is hundreds of posts on this topic alone. You have to remember the community here at sitepoint is quite large and so chances are the answer you seek is already here.

    http://www.sitepoint.com/forums/sear...earchid=974528

    also lookup in the manual implode (http://www.php.net/implode)

    goodluck

  3. #3
    SitePoint Zealot David C's Avatar
    Join Date
    Nov 2003
    Location
    New York!
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can use an array:

    PHP Code:
    extract($_POST['fix']); // Just to give us a $fix array; make sure it's secure
    foreach ($fix as $id => $on)
    {
      if (
    $on)
      {
        
    // Checkbox clicked, do logic
      
    }
      else
      {
        
    // Not selected, do something else
      
    }



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
  •