I am trying to update my database with a post that a user has edited in a forum. The whole edit form is functioning excet for when they click edit the form submits and goes to the main forum page, but the database and the post doesn't change.
When the submit edit button is pressed I have this:
<input name="a_id" type="hidden" value="<? echo $rows['a_id']; ?>">
<input name="question_id" type="hidden" value="<? echo $rows['question_id']; ?>">
<input type="submit" name="Submit" value="edit post">
My save edit code is this:
#data preparation for the query
$id=intval($_POST['id']);
$a_id=intval($_POST['a_id']);
$question_id=intval($_POST['question_id']);
foreach ($_POST as $key => $value)
$_POST[$key] = mysql_real_escape_string($value);
$sql = "UPDATE $tbl_name SET a_answer='$_POST[a_answer]' WHERE a_id='$a_id' AND question_id='$question_id'";
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
mysql_close;
header ("location: main_forum.php");
?>
Any ideas???
EDIT
For those who find this question useful unlike @mario, the problem was in the variable I was sending to the save edit page.
<input name="a_id" type="hidden" value="<? echo $rows['a_id']; ?>">
<input name="question_id" type="hidden" value="<? echo $rows['question_id']; ?>">
Should have been
<input name="a_id" type="hidden" value="<? echo $a_id; ?>">
<input name="question_id" type="hidden" value="<? echo $question_id; ?>">