SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Apr 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    checkbox arrays php

    Hi

    Im using the following code to create checkboxes in a form. What I need, is the boxes the user checked, to remain checked after the form has been submitted. The reason for this is so that the user will not have to re-check the boxes if they would like to submit the form again. How can I do this using php code ?

    PHP Code:
    if ($db_found) {

        
    $sql="select cname, cid from course";

        
    //query the database
        
    $rs=mysql_query($sql) or die($sql.">>".mysql_error());

        
    //count how many records found
        
    $num=mysql_num_rows($rs);

    if(
    $num>0){ //check if
    <FORM NAME ="form1" METHOD ="POST" ACTION ="student_reg.php">
    //create array loop
        
    while($row=mysql_fetch_array($rs)){

            
    // extract row and echo the array
            
    extract($row);

        echo 
    "$cname"."<Input type = 'Checkbox' Name ='chk1[]' value ='$cid'>";

    }

        <
    INPUT TYPE "Submit" Name "Submit1"  VALUE "Register">


        </
    FORM>
    }



  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    if $cid is in array $_POST['chk1'], add 'checked' to the echo.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


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
  •