|
Posted by Aaron Reimann on 10/18/06 14:56
I have a lot of check boxes. This is an update of the check boxes, I
want something was checked, then to do an insert (which is currently
working), if something is no longer checked...delete the checkbox
join/link that is in the database.
So, the insert/checked is working, but the "unchecking" is not working.
I don't know how to compare an array of what was not checked.
Here is my code:
if (is_array($_POST['commentsid'])) {
foreach ($_POST['commentsid'] as $id) {
##########
## Finding out if it was previously checked
## if not, insert the data
##checking if this $id is already in the database
$query = mysql_query("SELECT id_ministry FROM join_comments WHERE
id_ministry = '$id'")
or die("Bad query: ".mysql_error());
## if it is not in the database, insert the id
if (mysql_num_rows($query) == "0") {
$insert =
"INSERT INTO ".
"join_comments (username, creation_stamp, id_people, id_ministry) ".
"VALUES ('$_SESSION[valid_user]', '$datetime', '$_POST[id]',
'$id')";
$mysql_insert = mysql_query($insert, $mysql_link)
or die("Bad query: ".mysql_error());
######
### i don't think this needs to be here. i think my delete needs to
be before everything
} elseif ((mysql_num_rows($query) == "1") && ($id == )) {
$deletequery = mysql_query("DELETE FROM join_comments WHERE
id_people = '$_POST[id]' AND id_ministry ='$id'")
or die("Bad query: ".mysql_error());
##
######
} else {
print "Error";
}
##
##########
}
}
I think I need to do my delete before everything. He is an "english"
version of what I think needs to be done:
do a query selected all that is in the database
compare what was checked this time against was is checked now
if something is no longer checked {
delete from database the ones that are not in the database now
}
}
I hope this makes sense.
Thank you for any help,
aaron
Navigation:
[Reply to this message]
|