PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
This bit of code below is to delete an answer from my forum, then once deleted to go to the question table in mysql and - 1 off the reply column for the question the answer has just been deleted off, the answer is being deleted but the reply column is not dropping down one, wondering if any one can help me, the code for it is shown below.
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// Get values from form.
$id=$_GET['a_id'];
// Do delete statement.
mysql_query("delete from forum_answer where a_id='$id'");
$tbl_name2="forum_question"; // Switch to table "forum_question"
// Get values from form.
$id=$_GET['id'];
// Do delete statement.
mysql_query("UPDATE forum_question SET reply = reply - 1 WHERE id = $id");
// Close database connection
mysql_close();
// Redirect to select.php.
header("location:main_forum.php");
This is the part that i believe to be the problem not sure whether ive written it right
$tbl_name2="forum_question"; // Switch to table "forum_question"
// Get values from form.
$id=$_GET['id'];
// Do delete statement.
mysql_query("UPDATE forum_question SET reply = reply - 1 WHERE id = $id");
yeah guess so but i was after it to just delete one answer, the one im deleting, but its deleted every answer in the table, and from what i can see even though it says it has adjust the reply column i cant see it has done this as the figues all seem the same.
If it deletes more records than you want then either your condition where a_id=$id is wrong or the value you assign to the field a_id when inserting a new reocrd.