Forum Moderators: coopster
echo "<pre>";
print_r($_POST);
echo "</pre>";
//if any LCNS_REQ boxes are checked do the following
if ($LCNS_REQ_NM!= "")
{
while (list($key, $value) = each($LCNS_REQ_NM))
{
//find LCNS_REQ_CDs for boxes checked on form
$query = "SELECT license_reqs.LCNS_REQ_CD FROM license_reqs WHERE license_reqs.LCNS_REQ_NM = '$value'";
$result1 = mysql_query($query)
or die ("Couldn't execute get license_reqs_cd query.");
$row = mysql_num_rows($result1);
while ($row = mysql_fetch_array($result1))
{
extract($row);
$ischecked = trim("$row[LCNS_REQ_CD]");
echo "ischecked = $ischecked<BR>";
}
//find LCNS_REQ_CDs already in table
$query = "SELECT license_lcnsreqs.LCNS_REQ_CD FROM license_lcnsreqs WHERE license_lcnsreqs.LCNS_CD = '$LCNS_CD'";
$result2 = mysql_query($query)
or die ("Couldn't execute get license_lcnsreqs_cd query.");
$row = mysql_num_rows($result2);
while ($row = mysql_fetch_array($result2))
{
extract($row);
$issaved = trim("$row[LCNS_REQ_CD]");
echo "issaved = $issaved<BR>";
}
//delete LCNS_REQ_CD if unchecked and!= 3 (none selected but needed to generate checkbox html)
$intable = ($issaved == $ischecked);
echo "intable = $intable<BR>";
if ($intable!= 1)
{
$query = "DELETE FROM license_lcnsreqs WHERE (LCNS_CD='$LCNS_CD' AND LCNS_REQ_CD='$issaved' AND '$issaved'!= '3')";
$result = mysql_query($query)
or die ("Couldn't execute delete license_lcnsreqs query.");
}
//insert LCNS_REQ_CD if checked and not already in table
$notintable = ($ischecked!= $issaved);
echo "notintable = $notintable<BR>";
if ($notintable == 1)
{
$query = "INSERT INTO license_lcnsreqs (LCNS_CD,LCNS_REQ_CD) VALUES ('$LCNS_CD','$ischecked')";
$result = mysql_query($query)
or die ("Couldn't execute insert new license_lcnsreqs query.");
}
}
}
Thanks for your help!
Don't be embarrassed, this is a somewhat more advanced task. The trick is to recognize which values already exist in the database table and which values the user has now selected as those to keep. Arrays work well in these instances. In pseudocode: