Forum Moderators: coopster
<input type=\"checkbox\" name=\"box".$boxId."[]\" value=\"".$fields['boxvalue']."\" ".((in_array($fields['boxvalue'],$selectedValue))?"checked":"")."> $getFields = mysql_query("SELECT DISTINCT boxid, boxname, boxtype, active FROM opfields WHERE (categoryid='".$cat."' or categoryid='0') AND (productid='$row[product]' or productid='0')") or die(mysql_error());
$isFields = mysql_num_rows($getFields);
if ($isFields) {
while ($fields=mysql_fetch_array($getFields)) {
$box_value = "";
if ($fields['boxtype']=="checkbox") {
for ($i=0; $i<count($_POST['box'.$fields['boxid']]); $i++)
$box_value .= $_POST['box'.$fields['boxid']][$i]."+";
} else {
$box_value = $_POST['box'.$fields['boxid']];//for radio
}
if ($fields['boxtype']=="checkbox") {
if ($box_value!=='') {
$addFieldData = mysql_query("INSERT INTO opfields_data
(prodid, custid, boxid, boxname, boxvalue, monetary, boxtype) VALUES
('".$_GET[product]."','".$ses."','".$fields['boxid']."','".$fields['boxname']."', '".remSpecialChars($box_value)."','".remSpecialChars($box_value)."','".$fields['boxtype']."')") or die(mysql_error());
}
}else if ($fields['boxtype']=="radio") {
[edited by: dreamcatcher at 8:21 am (utc) on Mar. 23, 2007]
[edit reason] Fixed side scroll. [/edit]
You want to insert one row for radio and N rows for checkbox, eg. when sb checked 4 checkboxes you want to insert 4 times?
then:
$getFields = mysql_query("SELECT DISTINCT boxid, boxname, boxtype, active
FROM opfields
WHERE (categoryid='".$cat."' OR categoryid='0')
AND (productid='$row[product]' OR productid='0')") or die(mysql_error());
$isFields = mysql_num_rows($getFields);if ($isFields) {
while ($fields=mysql_fetch_array($getFields)) {
if ($fields['boxtype']=="checkbox") {
for ($i=0; $i<count($_POST['box'.$fields['boxid']]); $i++)$addFieldData = mysql_query("INSERT INTO opfields_data
(prodid, custid, boxid, boxname, boxvalue, monetary, boxtype) VALUES
('".$_GET[product]."','".$ses."','".$fields['boxid']."','".$fields['boxname']."', '".remSpecialChars($_POST['box'.$fields['boxid']][$i])."','".remSpecialChars($_POST['box'.$fields['boxid']][$i])."','".$fields['boxtype']."')") or die(mysql_error());} else {
$addFieldData = mysql_query("INSERT INTO opfields_data
(prodid, custid, boxid, boxname, boxvalue, monetary, boxtype) VALUES
('".$_GET[product]."','".$ses."','".$fields['boxid']."','".$fields['boxname']."', '".remSpecialChars($_POST['box'.$fields['boxid']])."','".remSpecialChars($_POST['box'.$fields['boxid']])."','".$fields['boxtype']."')") or die(mysql_error());}
}
}
Hope this is what you want.
Michal