i am doing reply page for forum, users can reply for the specific topic they would like to reply. Firstly of all, when click the topic name in topic page. i will redirect them to reply page. the details of the topic will be retrieved from database, like 'detail' field, 'name'( name of the poster) 'email', 'date'. secondly, i will also retrieve all the replies from other users. and lastly is creating text box and text area to let the user to reply to this speicific topic.
my code is in reply page is in the following :
Expand|Select|Wrap|Line Numbers
- <?php
- date_default_timezone_set('Asia/Singapore');
- mysql_connect('localhost','root','') or die(mysql_error());
- mysql_select_db('member') or die(mysql_error());
- // get value of id that sent from address bar
- $id=$_GET['id'];
- $sql="SELECT * FROM forum_question WHERE id='$id'";
- $result=mysql_query($sql) or die(mysql_error());
- $rows=mysql_fetch_array($result);
- ?>
- <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
- <tr>
- <td><table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="1" bgcolor="#FFFFFF">
- <tr>
- <td bgcolor="#F8F7F1"><strong><? echo $rows['topic']; ?></strong></td>
- </tr>
- <tr>
- <td bgcolor="#F8F7F1"><strong>Detail :</strong><? echo $rows['detail']; ?></td>
- </tr>
- <tr>
- <td bgcolor="#F8F7F1"><strong>By :</strong> <? echo $rows['name']; ?> </td>
- </tr>
- <tr>
- <td bgcolor="#F8F7F1"><strong>Email : </strong><? echo $rows['email'];?></td>
- </tr>
- <tr>
- <td bgcolor="#F8F7F1"><strong>Date/time : </strong><? echo $rows['datetime']; ?></td>
- </tr>
- </table></td>
- </tr>
- </table>
- <BR>
- <?php
- //$tbl_name2="forum_answer"; // Switch to table "forum_answer"
- $sql2="SELECT * FROM forum_answer WHERE q_id = '$id'";
- $result2=mysql_query($sql2) or die(mysql_error());
- while($rows=mysql_fetch_array($result2)){
- ?>
- <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
- <tr>
- <td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
- <tr>
- <td bgcolor="#F8F7F1"><strong>ID</strong></td>
- <td bgcolor="#F8F7F1">:</td>
- <td bgcolor="#F8F7F1"><? echo $rows['a_id']; ?></td>
- </tr>
- <tr>
- <td width="18%" bgcolor="#F8F7F1"><strong>Name</strong></td>
- <td width="5%" bgcolor="#F8F7F1">:</td>
- <td width="77%" bgcolor="#F8F7F1"><? echo $rows['a_name']; ?></td>
- </tr>
- <tr>
- <td bgcolor="#F8F7F1"><strong>Email</strong></td>
- <td bgcolor="#F8F7F1">:</td>
- <td bgcolor="#F8F7F1"><? echo $rows['a_email']; ?></td>
- </tr>
- <tr>
- <td bgcolor="#F8F7F1"><strong>Comment</strong></td>
- <td bgcolor="#F8F7F1">:</td>
- <td bgcolor="#F8F7F1"><? echo $rows['a_answer']; ?></td>
- </tr>
- <tr>
- <td bgcolor="#F8F7F1"><strong>Date/Time</strong></td>
- <td bgcolor="#F8F7F1">:</td>
- <td bgcolor="#F8F7F1"><? echo $rows['a_datetime']; ?></td>
- </tr>
- </table></td>
- </tr>
- </table><br>
- <?
- }
- $sql3="SELECT view FROM forum_question WHERE id ='$id'";
- $result3=mysql_query($sql3) or die(mysql_error());
- $rows=mysql_fetch_array($result3);
- $view=$rows['view'];
- // if have no counter value set counter = 1
- if(empty($view)){
- $view=1;
- $sql4="INSERT INTO forum_question(view) VALUES('$view') WHERE id ='$id'";
- $result4=mysql_query($sql4) or die(mysql_error());
- }
- // count more value
- else{
- $addview=$view+1;
- $sql5="update forum_question set view ='$addview' WHERE id ='$id'";
- $result5=mysql_query($sql5) or die(mysql_error());
- }
- ?>
- <BR>
- <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
- <tr>
- <form name="form1" method="post" action="add_answer.php">
- <td>
- <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
- <tr>
- <td width="18%"><strong>Name</strong></td>
- <td width="3%">:</td>
- <td width="79%"><input name="a_name" type="text" id="a_name" size="45"></td>
- </tr>
- <tr>
- <td><strong>Email</strong></td>
- <td>:</td>
- <td><input name="a_email" type="text" id="a_email" size="45"></td>
- </tr>
- <tr>
- <td valign="top"><strong>Comment</strong></td>
- <td valign="top">:</td>
- <td><textarea name="a_answer" cols="45" rows="3" id="a_answer"></textarea></td>
- </tr>
- <tr>
- <td> </td>
- <td><input name="id" type="hidden" value="<? echo $id; ?>"></td>
- <td><input type="submit" name="Submit" value="Submit"></td>
- </tr>
- </table>
- </td>
- </form>
- </tr>
- </table>
- <BR><BR>
- <?
- echo"<div align='center'><a href ='main_forum.php'>Back to Forum Home page</a></div>";
- ?>
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id ='15'' at line 1"
i don;t know where is wrong with it. can any one help me to check where of the syntax is wrong.
PS my database structure is like this, in forum_question table , i have id as primay key, userid as foreign key, the rest of the field is name, topic, detail, email,datetime, view, reply. ( view and reply is to a field to count how many people have been viewed or replied to the topic)
in fourm_answer table, we got a_id as primary key, q_id as foreign key( it is the same as id in forum_question table), the rest of field is a_name,a_email,a_answer,a_datetime.
any one can help me with this, it is urgent, as my project timeline is very near. thanks in advance for your kind help! :)