www.webdeveloper.com
Results 1 to 2 of 2

Thread: Checkbox checked (associated tables) - editing with PHP mySQL

  1. #1
    Join Date
    Sep 2012
    Posts
    1

    Checkbox checked (associated tables) - editing with PHP mySQL

    Hello guys

    I have a small problem and please help to resolve this.
    I have associated categories in the database. During the edit, i need, that
    categories which were checked when first somebody added his/her info that categories to be selected...

    In my picture is described what i want to do.

    http://img18.imageshack.us/img18/3104/capqy.jpg

    Thanks for advice...

    And here is my code
    PHP Code:
    <?php
    include ("db.php");
    if (isset(
    $_GET['id'])) {$id $_GET['id'];}

    if (!isset(
    $id))
    {
    $result mysql_query("SELECT id, name, sur FROM info");      
    $myrow mysql_fetch_array($result);
    do 
    {
    printf ("<p style='float:left; margin-left:6px;'> &nbsp;<a href='edit.php?id=%s'>%s</a>&nbsp;&nbsp;|</p>",$myrow["id"],$myrow["name"]);
    }
    while (
    $myrow mysql_fetch_array($result));
    }
    else
    {
        
               
    $result2 mysql_query("SELECT * FROM info WHERE id=$id");      
    $myrow2 mysql_fetch_array($result2);

    $sql "SELECT cat_id, cat_name FROM category";
    $res mysql_query($sql) or die(mysql_error());
        
    $checkboxes '';
    while (list(
    $id$cat) = mysql_fetch_row($res)) {
    $checkboxes .= "<input type='checkbox' name='category[]' value='$id' /> $cat<br />";
    }

    print <<<HERE

    <form method = 'post' action = 'update.php' >
        Name: <input type='text' name='name' value="
    $myrow2[name]" size='50' /><br />
        Surname: <input type='text' name='sur' value="
    $myrow2[sur]" size='50' /><br />
        Categories:<br />
        
    $checkboxes
        <input type='submit' name='btnSubmit' value='Submit' />
    </form>

    HERE;
    }
    ?>

  2. #2
    Join Date
    Jan 2004
    Posts
    484
    you may want to look up php form handeling checkbox

    then you'll need to need to add to you link table with an : insert

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles