I have 2 tables for a simple massage board, one for questions and one for answers.
The table forum_questions has a field called 'reply' with holds an int value for the number of answers the question has.
My problem is this:
I have a form to delete answers, you pick the question from a dropdown and the answers to that question are displayed with checkboxes for deletion. This works ok, but I'm stuck at how I then get it to decrement the 'reply' fiel in forum_question by the amount of answers that werwe removed.
This is my form
<form class='form2' action='forumadminpage.php' method='post' enctype='multipart/form-data' >
<b><span class='formheading'>Choose A Topic</span><br />To Remove Comments</b><br />
<select name="comments">
<?php echo $op;?>
</select>
<input type='submit' name='submit' value='Get Comments' />
<?php
include '../inc/connect.php';
if(isset($_POST['submit'])){
$comments= intval($_POST['comments']);
$data = mysqli_query($link, "SELECT * FROM forum_answer WHERE question_id IN ($comments) ")
or die(mysql_error());
while($info = mysqli_fetch_array( $data )) {
echo "<p>";
echo "<input type='checkbox' name='remove[{$info['id']}]' value='Remove' />";
echo $info['id'];
echo ': ';
echo $info['a_title'];
echo "</p>";
}
echo"<input type='submit' name='submit' value='Delete Comments' />";
}
?>
</form>
And this is the php to remove answers
<?php
if(isset($_POST['remove'])){
$chk = (array) $_POST['remove'];
$p = implode(',',array_keys($chk));
if ($sql = mysqli_query($link, "DELETE FROM forum_answer WHERE id IN ($p )")){
header( 'Location: forumadminpage.php' ) ;
}
else{
echo '<script type="text/javascript"> alert("Comments have not been removed, try again or contact site developer") </script>';
}
}
?>
Can anyone help here?
Thanks...