ciaran Posted May 6, 2007 Share Posted May 6, 2007 hey everybody , I am having a problem , I am building a forum application and I nearly have it completed , but I have a problem. The code below, should display the user's personal information and the comment's left by all the users. I have check it in the database and all the info is there and nothing wrong with the actaully code connect ups as I have tested with echo. here is the errorr I get. "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 '' at line 1" Hope some1 can help me , thanks <?php // Make a MySQL Connection mysql_connect("localhost", "username", "password") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); $threadid = $_GET['threadid']; // Retrieve all the data from the "$threadid" table $result3 = mysql_query("SELECT * FROM $threadid") or die(mysql_error()); $row3 = mysql_fetch_array( $result3 ); ////////////////// user id get end/////////////////// // Retrieve all the data from the "login" table $result2 = mysql_query("SELECT * FROM login WHERE id ='$row3[userid]'") or die(mysql_error()); while($row2 = mysql_fetch_array( $result2 )) { // Print out the contents of each row into a table echo "<tr><td width=\"100\">$row2[userid]</td>\n";} ////////////////////////User Id col extract information/////////////////////////////////////////// // Retrieve all the data from the "$threadid" table $result = mysql_query("SELECT * FROM $threadid") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<td align=\"top\">$row[comment]</td></tr>\n";} echo "</table></div>\n"; echo "<p id=\"menu2\"> <a class=\"menlinks\" href=\"addreplyform.php?threadid=$threadid\">Add Reply</a> <a class=\"menlinks\" href=\"#\">Report Aduse</a> <a class=\"menlinks\" href=\"#\">Time</a> </p>\n";?> Quote Link to comment https://forums.phpfreaks.com/topic/50222-solved-mysql-fetch-array-query-problem/ Share on other sites More sharing options...
paul2463 Posted May 6, 2007 Share Posted May 6, 2007 is the table called $threadid or is $threadid a variable?? if it is a variable then the query formation should look like this $result3 = mysql_query("SELECT * FROM '$threadid' ") Quote Link to comment https://forums.phpfreaks.com/topic/50222-solved-mysql-fetch-array-query-problem/#findComment-246537 Share on other sites More sharing options...
ciaran Posted May 6, 2007 Author Share Posted May 6, 2007 Thanks for your input but.... $threadid is a variable yes and I did what you said but still no joy. Getting this erorr now "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 ''thread31867'' at line 1" thread31867 is the name of a table in the database. Kind Regards Ciaran Mc Cann Quote Link to comment https://forums.phpfreaks.com/topic/50222-solved-mysql-fetch-array-query-problem/#findComment-246626 Share on other sites More sharing options...
paul2463 Posted May 6, 2007 Share Posted May 6, 2007 unfortunatley PHP / MySql does not agree with you, it is saying that it does not understand either the table name or the syntax of the query, did you use the syntax as I put it in my post?? is so then its the table name it does not like, have you connected ok to the correct database name? can you do me a favour, instead of executing the query can you echo out the query for me echo "SELECT * FROM '$threadid' "; to see if it is properly constituted Quote Link to comment https://forums.phpfreaks.com/topic/50222-solved-mysql-fetch-array-query-problem/#findComment-246649 Share on other sites More sharing options...
ciaran Posted May 6, 2007 Author Share Posted May 6, 2007 not sure what you mean me to do , will you post the code you would use, do I just use what you post and the $threadid = $_GET[uesrid]; or what. It connects to the database fine on the first piece of information added to it , but then when you add more its throws out that error. Quote Link to comment https://forums.phpfreaks.com/topic/50222-solved-mysql-fetch-array-query-problem/#findComment-246715 Share on other sites More sharing options...
ciaran Posted May 6, 2007 Author Share Posted May 6, 2007 I am just after fixing it. here is the code I used below , just put {} around the variable and it works fine. $result3 = mysql_query("SELECT * FROM {$threadid} ") Thanks for your help anyway Kind Regards Ciaran Mc Cann Quote Link to comment https://forums.phpfreaks.com/topic/50222-solved-mysql-fetch-array-query-problem/#findComment-246825 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.