save checkbox to database?

hello I want to save the checkbox in the db.
but this error keep showing.
Notice: Undefined index: training in

here is my code

form method=“post” action=“interface/regvalidation_GT.php”>

		Managerial Trainings: <br>

CEFE: Small Business Planning Course

CEFE Course on how to start a business

Accounting for Non Accountants

Basic Bookkeeping / Taxation and Business Experiential Workshop

Financial Management

Values Formation

Team Building

Leadership and Entrepreneurship Motivation Course

$training=serialize($_POST[‘training’]); //takes the data from a post operation…
//$training = mysql_real_escape_string(implode(’,’, $_POST[‘training’]));

$sql=“INSERT INTO pending (mtrainings) VALUES (’$training’)”;

your getting the error because $_POST[‘training’] is a variable…
and training[] is an array…

to fix it remove the [] from the training[]
:wink:

Red, I think what jpcatherine wants is - send array, not just value. So havign “training[]” as a name of checkboxes array will work. But the problem is that it need to be name=“training[]” NOT id=“training[]”. Check out this simple code:

[php]

<?php if($_POST["submit"] and is_array($_POST["training"])){ echo '
';
    print_r($_POST["training"]);
    echo '
'; echo '
'; } ?> CEFE: Small Business Planning Course
Financial Management
Values Formation
Team Building
Leadership and Entrepreneurship Motivation Course
[/php]

i stand corrected :slight_smile:

@ phphelp
thank you for your help.
But how can I save the array in the db?

You can either serialize it:
[php]$string = serialize($_POST[“training”]); // <-- you can save this in a text field in your db

// when you need to read array from db
$array = unserialize($string);
[/php]

OR use implode to concatenate elements of array into a string, for example with a delimiter pipe |
[php]$string = implode(’|’,$_POST[“training”]);[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service