forum reply help
Posted: Sun Apr 03, 2011 2:45 pm
Hi can anyone help and tell me whats wrong with this code?
<?php
include "connect.php";
// 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 reply 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_username'];
$a_answer=$_POST['a_reply'];
// Insert answer
$sql2="INSERT INTO reply(question_id, a_id, a_username, a_reply, a_date, a_time)VALUES('$id', '$Max_id', '$a_username', '$a_reply', CURDATE(), CURTIME())";
$result2=mysql_query($sql2);
if($result2){
echo "Successful<BR>";
echo "<a href='viewtopic.php?id=".$id."'>View your answer</a>";
// If added new answer, add value +1 in reply column
$sql3="UPDATE topic SET reply='$Max_id' WHERE id='$id'";
$result3=mysql_query($sql3);
}
else {
echo "ERROR";
}
mysql_close();
?>
but gives this error and dont know why?
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/fightwa1/public_html/addreply.php on line 10
please help Thanks
<?php
include "connect.php";
// 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 reply 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_username'];
$a_answer=$_POST['a_reply'];
// Insert answer
$sql2="INSERT INTO reply(question_id, a_id, a_username, a_reply, a_date, a_time)VALUES('$id', '$Max_id', '$a_username', '$a_reply', CURDATE(), CURTIME())";
$result2=mysql_query($sql2);
if($result2){
echo "Successful<BR>";
echo "<a href='viewtopic.php?id=".$id."'>View your answer</a>";
// If added new answer, add value +1 in reply column
$sql3="UPDATE topic SET reply='$Max_id' WHERE id='$id'";
$result3=mysql_query($sql3);
}
else {
echo "ERROR";
}
mysql_close();
?>
but gives this error and dont know why?
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/fightwa1/public_html/addreply.php on line 10
please help Thanks