Hello all,
I have a form that contains checkboxes to update a database with either "Yes" or "No" based on the user selection.
The check boxes are in an array with the values set to a "LinkID"
example:
<?php
//find the user's assigned links
$rowlink=$row_rsUpdate['LinkID'];
mysql_select_db($database_mambo, $mambo);
$query_rsAssignedLinks = "SELECT * FROM assignedlinks WHERE username = '$username' and ALID = '$rowlink' and `Add` ='Yes'";
$rsAssignedLinks = mysql_query($query_rsAssignedLinks, $mambo) or die(mysql_error());
$row_rsAssignedLinks = mysql_fetch_assoc($rsAssignedLinks);
$totalRows_rsAssignedLinks = mysql_num_rows($rsAssignedLinks);
?>
<input type="checkbox" name="Add[]" value="<? echo $row_rsUpdate['LinkID']; ?>"
<?php if (!$_POST && (!(strcmp($row_rsAssignedLinks['Add'],"Yes")))) { echo "checked=\"checked\"";} ?> <?php if ($_POST && (isset($_POST['Add'])=="1")) { echo "checked=\"checked\"";} ?> <?php $OK = isset($_POST['Add']) ? true : false; if($OK && $_POST['Add']=="Yes") { ?> <? } ?>/>
Add
I have the following insert statement that works as long as the values are "Yes":
if((isset($_POST["Submit"])) && ($_POST["MM_Update"] == "update"))
{
for($m=0;$m<count($_POST['Add']);$m++)
{
$add=$_POST['Add'][$m];
//find the correct MenuID
mysql_select_db($database_mambo, $mambo);
$query_rsMenuID = "SELECT * FROM `links` WHERE LinkID = '$add'";
$rsMenuID = mysql_query($query_rsMenuID, $mambo) or die(mysql_error());
$row_rsMenuID = mysql_fetch_assoc($rsMenuID);
$totalRows_rsMenuID = mysql_num_rows($rsMenuID);
$mid=$row_rsMenuID['MenuID'];
//find if there is already an assignedlink record written for the ALID
mysql_select_db($database_mambo, $mambo);
$query_rsALFind = "SELECT * FROM assignedlinks WHERE mambo_user_id = '$id' and `username` = '$username' AND ALID = '$add' AND `Add` = 'Yes'";
$rsALFind = mysql_query($query_rsALFind, $mambo) or die(mysql_error());
$row_rsALFind = mysql_fetch_assoc($rsALFind);
$totalRows_rsALFind = mysql_num_rows($rsALFind);
(!empty($_POST["Add"]))
{
while(list($k, $v) = each($_POST["Add"]))
{
$v= "Yes";
foreach($_POST['Add'] as $row=> $assigned)
{
$assigned= $assigned;
$MenuID = $_POST['menu'][$row];
$updateAddlinksYes = "UPDATE assignedlinks SET `Add`='$v' WHERE ALID='$assigned' AND `mambo_user_id`= '$id'";
$ResultAddlinksYes = mysql_query($updateAddlinksYes, $mambo) or die(mysql_error());
echo $updateAddlinksYes;
}
However, I need this to also update the datebase if the user unchecks the checkbox (BTW there are 4 checkboxes "Add", "Update" "Delete", and "View") or the checkbox has not been selected.
Can anyone point me in the right direction ?
Many thanks in advance!