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
forum reply help
Moderator: General Moderators
Re: forum reply help
Code: Select all
$result=mysql_query($sql);Code: Select all
$result=mysql_query($sql);
if(!$result){
//do some error handeling
}else{
$rows=mysql_fetch_array($result);
//process the rest of code
}Code: Select all
$id=mysql_real_escape_string($_POST['id']);Re: forum reply help
well it lets me enter a numerous replies but in only one topic and says error when I try and reply on another topic any suggestions?
Re: forum reply help
Is that the only error you get? or are there other errors?simmsy wrote: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/fightwa1/public_html/addreply.php on line 10
make sure you use mysql_real_escape_string() on every $_POST[] that you get.
Re: forum reply help
yea thats sorted now but it wont let me reply on multiple topics only on one?