-1

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

$Deeptissue="";

$Swedish="";

$Lomilomi="";

$checkbox=$_POST['typeTech'];

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

foreach($checkbox as $typeTech ) {

if($typeTech=="deeptissue")

$Deeptissue="Deep Tissue";

else if($typeTech=="swedish")

$Swedish="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)

VALUES('$typeTech')")

or die (mysql_error());

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

4
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by HasNor
0

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.

0

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

// -------- PARSING TECHNIQUES
if ($_POST['parse_var'] == "location"){
	
$checkbox=$_POST['typeTech'];
$techniques .= '';

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

foreach($checkbox as $typeTech ) {

if($typeTech=="deeptissue")

$Deeptissue="deeptissue";

else if($typeTech=="swedish")

$Swedish="swedish";

else if($typeTech=="lomilomi")

$Lomilomi="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?

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

0

Hi

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.

Edited by gazza7: n/a

0

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

<?php
include 'connection/db_connect.php';


if(isset($one))
 $val1=$one.";";
 else
 $val1=NULL;

if(isset($two))
 $val2=$two.";";
 else
 $val2=NULL;

if(isset($three))
  $val3=$three.";";
  else
 $val3=NULL;

$printVal=$val1."".$val2."".$val3;

$val=array($printVal);


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

    if($error ==0){


    foreach($val as $values)
    {


    if(!empty($values)){    
    $sql="INSERT INTO `request` (detail) values('$values')";

    mysql_query($sql);}

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

<html>
<body>
<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">
</form>

</body>
</html>

Edited by Dani: Formatting fixed

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.