francis Aneke Posted March 26, 2014 Share Posted March 26, 2014 Am designing a simple php forum platform in dreamweaver using mysql database,but when i run the script, on redirecting to a page called view_topic.com it shows this error message----> 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='4'' at line 1 The $topic_output normally echos out then followed by the above sql error message ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// <?php///Error reportingerror_reporting(E_ALL);ini_set('display errors','1');include_once("connect_to_mysql.php");$topic_output='';$id=$_GET['id'];$sql="SELECT * FROM forum_question WHERE `id`='".$_GET['id']."'";$result=mysql_query($sql) or die(mysql_error()); $row = mysql_fetch_array($result); $name=$row['name']; $topic=$row['topic']; $view=$row['view']; $reply=$row['reply']; $email=$row['email']; $detail=$row['detail']; $datetime=$row['datetime']; $topic_output=' <table width="900" height="127" border="0" cellpadding="2" cellspacing="4" align="center"> <tr> <th scope="col"><li style="color:#004200;"><h3>'.$topic.'</h3></li></th> </tr> <tr> <td bgcolor="#CCCCCC"><div><p width="500px">'.$detail.'</p></div></td> </tr> <tr> <td bgcolor="#004200"><li style="color:white;"><strong>By: '.$name.'</strong> <strong> Email: '.$email.'</strong></li></td> </tr> <tr> <td bgcolor="#004200"><li style="color:white;"><strong>Date/Time: <font>'.$datetime.'</strong></li></td> </tr> <tr> <td> </td> </tr> </table>'; ?> <?php///Error reportingerror_reporting(E_ALL);ini_set('display errors','1');$answer_output='';$sql2=mysql_query("SELECT * FROM forum_answer WHERE question_id='$id'") or die(mysql_error());$row=mysql_fetch_array($sql2);while($row){ $a_id=$row['a_id']; $a_name=$row['a_name']; $a_email=$row['a_email']; $a_answer=$row['a_answer']; $a_detail=$row['a_detail']; $a_datetime=$row['a_datetime']; $answer_output.=' <table width="600" height="127" border="0" cellpadding="2" cellspacing="4" align="center"> <tr> <td><li style="color:#004200;"><strong>By: '.$a_name.'</strong></li></td> </tr> <tr> <td bgcolor="#CCCCCC"><div><p width="500px" align="center">'.$a_detail.'</p></div></td> </tr> <tr> <td bgcolor="#004200"></li></td> </tr> <tr> <td bgcolor="#004200"><li style="color:white;"><strong>Date/Time: '.$a_datetime.' <strong> Email: '.$a_email.'</strong></strong></li></td> </tr> </table> '; }?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title></head><body><div align="center" style="margin:0px 24px 0px 24px" id="topic_output"><div align="center" style="margin:0px 24px 0px 24px" id="topic_output"> <?php echo $topic_output; ?></div><br /><br /><div align="center" style="margin:0px 24px 0px 24px" id="answer_output"> <?php echo $answer_output; ?></div><br /> <?php$sql3=mysql_query("SELECT view FROM forum_question WHERE id='$id'") or die(mysql_error()); $row = mysql_fetch_array($sql3); $view=$row['view']; ////if have no counter value set counter ==1 if($view=0){ $view=1; } $sql4=mysql_query("INSERT INTO forum_question(view) VALUE('$view') WHERE id='$id'") or die(mysql_error()); ///Count more values $addview=$view+1; $sql5=mysql_query("UPDATE forum_question SET view='$addview' WHERE id='$id'") or die(mysql_error()); mysql_close(); ?><br /><br /><br /><div align="left" style="margin:0px 0px 0px 24px" id="table"><form action="add_answer.php" method="POST"><table width="595" border="0" cellspacing="0" cellpadding="2"> <tr> <td width="203"><li style="color:#004200;">NAME:</li></td> <td width="386"><label for="a_name"></label> <input type="text" name="a_name" id="a_name" size="60"/></td> </tr> <tr> <td><li style="color:#004200;">EMAIL:</li></td> <td><input type="text" name="a_email" id="a_email" size="60"/></td> </tr> <tr> <td valign="bottom"><li style="color:#004200;">ANSWER:</li></td> <td><label for="a_answer"></label> <textarea name="a_answer" id="a_answer" cols="57" rows="10"></textarea></td> </tr> <tr> <td colspan="2"> <input type="submit" name="submit" id="submit" value="SUBMIT" /> <input type="reset" name="reset" id="submit2" value="RESET" /> </td> </tr></table><input name="id" type="hidden" value="<?php echo $id; ?>"/></form></div></div></body></html> Link to comment Share on other sites More sharing options...
Don E Posted March 26, 2014 Share Posted March 26, 2014 I skimmed through the code and noticed this: $id=$_GET['id'];$sql="SELECT * FROM forum_question WHERE `id`='".$_GET['id']."'"; Try changing to: $sql="SELECT * FROM forum_question WHERE id=".$_GET['id']; // you can use $id here as well since $id is given the value of $_GET['id']. Also make sure $_GET['id'] contains a value. Link to comment Share on other sites More sharing options...
francis Aneke Posted March 26, 2014 Author Share Posted March 26, 2014 I did that yet the sytax error still shows Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now