Jump to content

[SOLVED] MySQL fetch array / query problem ????


ciaran

Recommended Posts

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";?>

Link to comment
https://forums.phpfreaks.com/topic/50222-solved-mysql-fetch-array-query-problem/
Share on other sites

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

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.