Stored the checkbox value into database

Here i Want to create one model and create checkbox for that.

BUt here problem is that the checked value is not stored into the database.

How to stored checked value into database ?

Table Name -Course_detail

Table Field :- id course_name

CheckBox creation coading.


		&#036;data = CourseDetail::model()-&gt;findAll();

		foreach(&#036;data as &#036;button)


			//echo &#036;button-&gt;course_name;

			echo &#036;form-&gt;checkBox(&#036;model,'course_name');

			echo &#036;button-&gt;course_name .'&lt;br&gt;';



Please give me some idea about this.

Normally you can’t have more than one field per model attribute / field database.

What your code does is generate as many checkboxes named ‘(your-model-name)_course_name’ as there are records in CourseDetail model’s table; that’s wrong as per HTML standards, and will mess up with Yii’s validation Javascript and also the form action since it will find several items with the same name in $_POST array.

That said, I don’t really understand what you’re trying to do. Outside CourseDetail model, what other related table(s) do you have? Do you have a one-to-many or many-to-many relationship in the database?

Here i want to create one database

id course_name







i have genrate check box of the course_name.the id is a primarykey and auto increment.then i have create checkbox is dynamically then i have use this course_name into contact form. then i checked any checkbox then how they are store the checkbox value into database.

my another contact databse is:-

id int(3)

name varchar(50)

date date

email varchar(40)

qualification varchar(20)

ref_from varchar(40)

intrested_course varchar(20) // i want to store checked checkbox value into this filed

intrested_in_joining varchar(10)

How to stored the course_name checkbox checked value into the intrested_course field.

Ok, so I understand you have two tables and models, one for the courses (I will call it “Course”), one for the potential trainees (I’ll call it “Contact”).

I believe that like you want just one course per trainee, if I understand correctly you table schema. IN that case, I’ll advise you to use option (radio) buttons instead of checkboxes.

Well in your Contact model:

	<div class="row">

	<?php echo $form->labelEx($model,'intrested_course'); ?>

	<?php echo $form->radioButtonList($model,'intrested_course',

								  CHtml::listData(Course::model()->findAll(), 'id', 'course_name'),



		<?php echo $form->error($model,'intrested_course'); ?>


sorry Sir,

Here any student are inquiry for more than one subject then what can i do ?

here the requirement are the checkbox.

plz any suggestion about stored the checkbox checked value into database.

i also give the radio button for course_time.

Your database design is wrong.

You need a many_many table to store the relationships between users and courses they are interested in.

i have created the databse and in this databse i have three tables.

  1. contact -id,name,date,email,qualification,ref_from,intrested_course,intrested_in_joining

  2. course_detail- id,course_name(check box)

  3. joining_time -id,time(radio burron)

Here table course_detail field "course_name" are stored into the contact tables "intrested_course".they are to store the value into the database.

i haqve do the inquiry for for the institute.

this inquiry form are mail and stored into the database.the mail function is already i have done but the checkbox checked value are not stord into database and mail function.

i am so confused please help me What can i do?