473,396 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem of "reply" page in forum

hi

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
  1. <?php
  2.  
  3. date_default_timezone_set('Asia/Singapore');
  4. mysql_connect('localhost','root','') or die(mysql_error());
  5. mysql_select_db('member') or die(mysql_error());
  6.  
  7.  
  8.  
  9. // get value of id that sent from address bar
  10. $id=$_GET['id'];
  11.  
  12. $sql="SELECT * FROM forum_question WHERE id='$id'";
  13. $result=mysql_query($sql) or die(mysql_error());
  14.  
  15. $rows=mysql_fetch_array($result);
  16. ?>
  17. <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
  18. <tr>
  19. <td><table width="100%" border="0" cellpadding="3" cellspacing="1" bordercolor="1" bgcolor="#FFFFFF">
  20. <tr>
  21. <td bgcolor="#F8F7F1"><strong><? echo $rows['topic']; ?></strong></td>
  22. </tr>
  23.  
  24. <tr>
  25. <td bgcolor="#F8F7F1"><strong>Detail :</strong><? echo $rows['detail']; ?></td>
  26. </tr>
  27.  
  28. <tr>
  29. <td bgcolor="#F8F7F1"><strong>By :</strong> <? echo $rows['name']; ?> </td>
  30. </tr>
  31. <tr>
  32. <td bgcolor="#F8F7F1"><strong>Email : </strong><? echo $rows['email'];?></td>
  33. </tr>
  34.  
  35. <tr>
  36. <td bgcolor="#F8F7F1"><strong>Date/time : </strong><? echo $rows['datetime']; ?></td>
  37. </tr>
  38. </table></td>
  39. </tr>
  40. </table>
  41. <BR>
  42. <?php
  43. //$tbl_name2="forum_answer"; // Switch to table "forum_answer"
  44.  
  45. $sql2="SELECT * FROM forum_answer WHERE q_id = '$id'";
  46. $result2=mysql_query($sql2) or die(mysql_error());
  47.  
  48. while($rows=mysql_fetch_array($result2)){
  49. ?>
  50. <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
  51. <tr>
  52. <td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
  53. <tr>
  54. <td bgcolor="#F8F7F1"><strong>ID</strong></td>
  55. <td bgcolor="#F8F7F1">:</td>
  56. <td bgcolor="#F8F7F1"><? echo $rows['a_id']; ?></td>
  57. </tr>
  58. <tr>
  59. <td width="18%" bgcolor="#F8F7F1"><strong>Name</strong></td>
  60. <td width="5%" bgcolor="#F8F7F1">:</td>
  61. <td width="77%" bgcolor="#F8F7F1"><? echo $rows['a_name']; ?></td>
  62. </tr>
  63. <tr>
  64. <td bgcolor="#F8F7F1"><strong>Email</strong></td>
  65. <td bgcolor="#F8F7F1">:</td>
  66. <td bgcolor="#F8F7F1"><? echo $rows['a_email']; ?></td>
  67. </tr>
  68. <tr>
  69. <td bgcolor="#F8F7F1"><strong>Comment</strong></td>
  70. <td bgcolor="#F8F7F1">:</td>
  71. <td bgcolor="#F8F7F1"><? echo $rows['a_answer']; ?></td>
  72. </tr>
  73. <tr>
  74. <td bgcolor="#F8F7F1"><strong>Date/Time</strong></td>
  75. <td bgcolor="#F8F7F1">:</td>
  76. <td bgcolor="#F8F7F1"><? echo $rows['a_datetime']; ?></td>
  77. </tr>
  78. </table></td>
  79. </tr>
  80. </table><br>
  81.  
  82. <?
  83. }
  84.  
  85. $sql3="SELECT view FROM forum_question WHERE id ='$id'";
  86. $result3=mysql_query($sql3) or die(mysql_error());
  87.  
  88. $rows=mysql_fetch_array($result3);
  89. $view=$rows['view'];
  90.  
  91. // if have no counter value set counter = 1
  92. if(empty($view)){
  93. $view=1;
  94. $sql4="INSERT INTO forum_question(view) VALUES('$view') WHERE id ='$id'";
  95. $result4=mysql_query($sql4) or die(mysql_error());
  96. }
  97.  
  98. // count more value
  99. else{
  100. $addview=$view+1;
  101. $sql5="update forum_question set view ='$addview' WHERE id ='$id'";
  102. $result5=mysql_query($sql5) or die(mysql_error());
  103. }
  104. ?>
  105. <BR>
  106. <table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
  107. <tr>
  108. <form name="form1" method="post" action="add_answer.php">
  109. <td>
  110. <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
  111. <tr>
  112. <td width="18%"><strong>Name</strong></td>
  113. <td width="3%">:</td>
  114. <td width="79%"><input name="a_name" type="text" id="a_name" size="45"></td>
  115. </tr>
  116. <tr>
  117. <td><strong>Email</strong></td>
  118. <td>:</td>
  119. <td><input name="a_email" type="text" id="a_email" size="45"></td>
  120. </tr>
  121. <tr>
  122. <td valign="top"><strong>Comment</strong></td>
  123. <td valign="top">:</td>
  124. <td><textarea name="a_answer" cols="45" rows="3" id="a_answer"></textarea></td>
  125. </tr>
  126. <tr>
  127. <td>&nbsp;</td>
  128. <td><input name="id" type="hidden" value="<? echo $id; ?>"></td>
  129. <td><input type="submit" name="Submit" value="Submit"></td>
  130. </tr>
  131. </table>
  132. </td>
  133. </form>
  134. </tr>
  135. </table>
  136. <BR><BR>
  137. <?
  138. echo"<div align='center'><a href ='main_forum.php'>Back to Forum Home page</a></div>";
  139. ?>
  140.  
everytime i query, the error message will come out. saying "
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! :)
Jul 11 '07 #1
3 1819
code green
1,726 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. $sql5="update forum_question set view ='$addview' WHERE id ='$id'";
Ideally when comparing numeric values leave out the quotes
Expand|Select|Wrap|Line Numbers
  1. WHERE id = $id
But this should not have caused the error.
I suspect there is sometnig wayward with the $addview variable.
Echo out the whole query before submitting and lets have a look at it.
[PHP]echo $sql5;[/PHP] This should be done anyway when developing otherwise you are blind. I am being nice today.
Jul 12 '07 #2
mwasif
802 Expert 512MB
Alway stry to identify where you are having issue. You have a lot of queries with the same WHERE clause, it is difficult for someone to identify the problem.

You have problem with this INSERT statement
[PHP]$sql4="INSERT INTO forum_question(view) VALUES('$view') WHERE id ='$id'";[/PHP]
It should be like this
[PHP]$sql4="INSERT INTO forum_question(id, view) VALUES($id, '$view')";[/PHP]

You can not use WHERE in INSERT statement. If id column is autoincrement, then simply don't include this in the query e.g.
[PHP]$sql4="INSERT INTO forum_question(view) VALUES('$view')";[/PHP]
Jul 12 '07 #3
ilearneditonline
130 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. // get value of id that sent from address bar
  2. $id=$_GET['id'];
  3.  
  4. $sql="SELECT * FROM forum_question WHERE id='$id'";
Not sure if this is the problem, but I know i have this all the time. A query string value is always a string. so what you should try is..

Expand|Select|Wrap|Line Numbers
  1. $id = (int)$_GET['id'];
That will convert your string value to an integer, assuming the id field is an integer in your database.
Jul 12 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: mike | last post by:
regards: I write java code to simulate my machine as a HTTP server, what is the "MUST REPLY" HTTP response headers? In my small survey,I think there are 2 "MUST REPLY" HTTP response headers....
0
by: Richard \(MrBonus\) | last post by:
I have made a project using a UDP client in VB.NET but am experiencing problems with receiving datagrams beyond a certain size (between 1300 and 1500 bytes). I'm contacting a gaming server (Medal...
10
by: Khamal | last post by:
Hello... The quality of reply is quite bad in this forum.....many post has not reply.... I/We need Microsoft technical team involve directly in this forum and put some effort to give us HELP. If...
3
by: Frank | last post by:
I am attempting to develop a solution where I handle bounced e-mails. I wish to field all bounced emails in a custom email account such a bounced@mycompany.com From the aricle at...
0
by: 2Barter.net | last post by:
newsmail@reuters.uk.ed10.net Fwd: Money for New Orleans, AL & GA Inbox Reply Reply to all Forward Print Add 2Barter.net to Contacts list Delete this message Report phishing Show original
12
by: DMcN | last post by:
Firstly this is my first post so thanks in advance for any help. I have created a form in my web page using Flash and all the variables seem OK. So now I have set up the CGI form on my web server...
1
by: stef mientki | last post by:
hello, I'm always have great difficulties, replying to this beautiful and helpful list. When I hit the reply button, the message is sent personally to the sender and not to the list. I've...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.