www.webdeveloper.com
Results 1 to 4 of 4

Thread: Creating a register

  1. #1
    Join Date
    Oct 2005
    Posts
    593

    Creating a register

    Hi there,

    Id like to create a manual register system but am not sure how to do parts of this.. I would like to list all the names of the people in my database (tblGroup) along with a textbox next to the name. When the user clicks submit, it will add all the people with a tick in the tickbox into the DB (tblRegister)

    Im only really stuck on the tickbox part...

    Fet

  2. #2
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    You would do this like any checkbox but you would assign a name with [] following it. For example, instead of giving each person's checkbox a separate name, you'd call all the checkboxes the same: userchkbox[].

    The result will be that in your action page, all the ones that have been clicked will be available to you under $_POST['userchkbox'], which will be an array over which you can loop and, one by one, insert in tblRegister.

    Make sense?

  3. #3
    Join Date
    Oct 2005
    Posts
    593
    Erm..Not really, i havent really done anything with arrays or such before... Can you explain a little more?

    Fet

  4. #4
    Join Date
    Dec 2006
    Location
    Escaz˙ (Costa Rica) and Mallorca (Spain)
    Posts
    3,234
    In your form or form part of you script, introduce something like this to retrieve the user names from the table:
    PHP Code:
    $sql "SELECT * FROM tblGroup ORDER BY user_name ASC";
    $qry mysql_query($sql) or die("SQL Error: $sql<br>" mysql_error());

    WHILE (
    $r mysql_query($qry)) :
      echo 
    "<input type='checkbox' name='frm_user_name[]' value='" $r['user_name'] . "'>" $r['user_name'] . "<br>";
    ENDWHILE;
    //rest of form...
    ?> 
    When you're ready to process the form, you would retrieve the checked user names as follows:
    PHP Code:
    $arrUserList $_POST['frm_user_name'];
    FOREACH (
    $arrUserList as $key => $thisUSER) :
      echo 
    "or whatever you want to do with " $thisUSER "<br>";
    ENDFOREACH; 
    Something to consider: If you're going to store a list of users, you should store their user ID rather than user name as above.

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