Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML HTML Basics

checkbox arrays php

Discussing Html . Code , Software , other

Moderators: macek, egami, gesf

checkbox arrays php

Postby virtualk » Tue Apr 09, 2013 1:13 am


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 ?

Code: Select all
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

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

      // extract row and echo the array

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


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


New php-forum User
New php-forum User
Posts: 1
Joined: Tue Apr 09, 2013 1:10 am

Re: checkbox arrays php

Postby sandeep605085 » Tue Apr 09, 2013 4:00 am

you can post the form to same page and can do the operation of student_reg.php in the same page so that the form will remain there.
then you can recheck the checked boxes by using the posted parameters of the checked check boxes.
User avatar
New php-forum User
New php-forum User
Posts: 44
Joined: Tue Feb 26, 2013 6:00 am
Location: Mindfire Solutions

Return to HTML Basics

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.