ironside82 Posted March 28, 2007 Share Posted March 28, 2007 I've been battling this code all day and it keeps returning the Error at the bottom of the code. Could someone cast their eye over it to see where i'm going wrong: <?php include("connect.php"); $tbl_name="forum_question"; // Table name // Get value of id that sent from hidden field $id=$_POST['id']; // Find highest answer number. $sql="SELECT MAX(a_id) AS Maxa_id FROM $tbl_name WHERE question_id='$id'"; $result=mysql_query($sql); $rows=@mysql_fetch_array($result); // add + 1 to highest answer number and keep it in variable name "$Max_id". if there no answer yet set it = 1 if ($rows) { $Max_id = $rows['Maxa_id']+1; } else { $Max_id = 1; } // get values that sent from form $a_name=$_POST['a_name']; $a_answer=$_POST['a_answer']; $datetime=date("d/m/y H:i:s"); // create date and time // Insert answer $sql2="INSERT INTO $tbl_name (question_id, a_id, a_name, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_answer', '$datetime')"; $result2=mysql_query($sql2); if($result2){ echo "Successful<BR>"; echo "<a href='view_topic.php?id=".$id."'>View your answer</a>"; // If added new answer, add value +1 in reply column $tbl_name2="forum_question"; $sql3="UPDATE $tbl_name2 SET reply='$Max_id' WHERE id='$id'"; $result3=mysql_query($sql3); } else { echo "ERROR"; } mysql_close(); ?> Thanks a lot James Quote Link to comment Share on other sites More sharing options...
per1os Posted March 28, 2007 Share Posted March 28, 2007 // Insert answer $sql2="INSERT INTO $tbl_name (question_id, a_id, a_name, a_answer, a_datetime)VALUES('$id', '$Max_id', '$a_name', '$a_answer', '$datetime')"; $result2=mysql_query($sql2) or die(mysql_error()); if(mysql_num_rows($result2) > 0){ Try that. Quote Link to comment Share on other sites More sharing options...
ironside82 Posted March 29, 2007 Author Share Posted March 29, 2007 Thats great frost110, The replys are now being posted but the error is still popping up. I believe its now something to do with the reply count not changing in the last bit of the script: Check: if($result2){ echo "Successful<BR>"; echo "<a href='view_topic.php?id=".$id."'>View your answer</a>"; // If added new answer, add value +1 in reply column $tbl_name2="forum_question"; $sql3="UPDATE $tbl_name2 SET reply='$Max_id' WHERE id='$id'"; $result3=mysql_query($sql3); } else { echo "ERROR"; } mysql_close(); ?> Quote Link to comment Share on other sites More sharing options...
btherl Posted March 29, 2007 Share Posted March 29, 2007 Actually it should be mysql_affected_rows(), not mysql_num_rows() See the description here: http://sg2.php.net/manual/en/function.mysql-num-rows.php Quote Link to comment Share on other sites More sharing options...
ironside82 Posted March 29, 2007 Author Share Posted March 29, 2007 Still not cracked it. :s Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.