Hello everyone,

I'm working on adding checkboxes to the edit_profile section where members should be able choose with checkboxes the multiple options of massage techniques offered... When I checked only one, either, option 1, or option 2 or option 3 I'm able to see it in the column in the correct table of mysql but when I check more then one box only the last box would insert into the column, ignoring the rest. In this case, if I check the three options, only lomi lomi would insert into the column... I hope you guys can help me. Here is the code:

// set all checkboxes to false initially





//if appear in the POST, they are checked, set to true

foreach($checkbox as $typeTech ) {


$Deeptissue="Deep Tissue";

else if($typeTech=="swedish")


else if($typeTech=="lomilomi")

$Lomilomi="Lomi Lomi";


echo "Technique checked: ".$Deeptissue."<br/>\n";

echo "Tchnique checked: ".$Swedish."<br/>\n";

echo "Technique checked: ".$Lomilomi."<br/>\n";

$sql = mysql_query("INSERT INTO Members (Technique)


or die (mysql_error());

Recommended Answers

All 4 Replies

It appears that you are using the same name for each textbox, typeTech? If so, only the last one on the page will be POSTed, try giving them different names, like 'deeptissue' then the POST value will be true or false, and you can test echo after a bunch of if statements.

Thanks so much... I already fixed it with the following code:

if ($_POST['parse_var'] == "location"){
$techniques .= '';

//if appear in the POST, they are checked, set to true

foreach($checkbox as $typeTech ) {



else if($typeTech=="swedish")


else if($typeTech=="lomilomi")


$techniques.= $typeTech.', ';

However, when I click on the update button without checking any boxes I get the following error:

Notice: Undefined index: typeTech in /home/massage/public_html/editprofile.php on line 109

Warning: Invalid argument supplied for foreach() in /home/massage/public_html/edit_profile.php on line 113

Any idea why?


Why don't you add a if else that if $_POST['typeTech' is empty than $typeTech = "no entry"; Then send this to mysql.

at least you know nothing has been entered.

I need someone help to solve my problem. hurm..why it didn't insert the value in the database haaa?

include 'connection/db_connect.php';






if(isset($_POST['Submit'])) {

    if($error ==0){

    foreach($val as $values)

    $sql="INSERT INTO `request` (detail) values('$values')";


if (mysql_error()) trigger_error(mysql_error());
} }?>

<form name="frm" method="POST" action="<?php $_SERVER['PHP_SELF']; ?> "  enctype="multipart/form-data">
<input name="one" type="checkbox" value="$one" /> One
<input name="two" type="checkbox" value="$two" /> Two
<input name="three" type="checkbox" value="$three" /> Three
<input type="submit" name="submit" value="submit">

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.