Page 1 of 1

Parse error

Posted: Sun Jun 22, 2003 4:59 am
by Gappa
Getting an prase error on line 13

Code: Select all

<html>
<head>
<title> Rantage.tk :: News ::</title>
</head>
<body>

<table border=0 width=100%>
<?php
$db = mysql_connect("localhost", "Gappa", ""); 
mysql_select_db("Gappa",$db); 
 

$query = SELECT topic_title, topic_id, FROM_UNIXTIME(topic_time,"%W the %D %M @ %r") AS Topic_Date, post_text, username FROM (phpbb_topics RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id) RIGHT JOIN phpbb_users ON topic_poster=(user_id WHERE forum_id=6) ORDER BY topic_time; 



$result = mysql_query($query, $db) or die ($query .': '.mysql_error()); 



while($row = mysql_fetch_assoc($result)) {


echo "<b><FONT FACE=Arial SIZE=-1 COLOR=#FF9900>"; 
echo "$row[topic_title]:</FONT></b><br/>"; 
echo "<FONT FACE=Arail SIZE=-2 COLOR=#999999>posted by: <b>$row[username]</b>"; 
echo " on: "; 
echo "$row[Topic_Date]</FONT><br/><hr><br/>"; 
echo "<FONT FACE=Arail SIZE=-1 COLOR=#FFFFFF> $row[post_text]</FONT>"; 
echo "<br/><br/>";  
echo "<FONT FACE=Arial SIZE=-2>"; 
echo "<a href="http://www.hostultra.com/~Gappa/phpBB2/viewtopic.php?t=$row[topic_id]"><b><FONT COLOR=#FF9900>Read comments</FONT></b></a></FONT>";
echo "<br/><br/><br/>";  
} 
?> 
</table>
</body>
</html>
Line 13 being..

Code: Select all

$query = SELECT topic_title, topic_id, FROM_UNIXTIME(topic_time,"%W the %D %M @ %r") AS Topic_Date, post_text, username FROM (phpbb_topics RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id) RIGHT JOIN phpbb_users ON topic_poster=(user_id WHERE forum_id=6) ORDER BY topic_time;
My eyes just arnt finding the error... i think
lil help please

Posted: Sun Jun 22, 2003 5:18 am
by twigletmac
There don't seem to be any quotes around that string. Try:

Code: Select all

$query = "SELECT topic_title, topic_id, FROM_UNIXTIME(topic_time,'%W the %D %M @ %r') AS Topic_Date, post_text, username FROM (phpbb_topics RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id) RIGHT JOIN phpbb_users ON topic_poster=(user_id WHERE forum_id=6) ORDER BY topic_time";
Mac

Posted: Sun Jun 22, 2003 5:19 am
by patrikG
Maybe put quotation-marks around your query?

Code: Select all

$query = "SELECT topic_title, topic_id, FROM_UNIXTIME(topic_time,'%W the %D %M @ %r') AS Topic_Date, post_text, username FROM (phpbb_topics RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id) RIGHT JOIN phpbb_users ON topic_poster=(user_id WHERE forum_id=6) ORDER BY topic_time;";

Posted: Sun Jun 22, 2003 5:23 am
by Gappa
Ahhh yes, ... still this gives me a different error now

SELECT topic_title, topic_id, FROM_UNIXTIME(topic_time,'%W the %D %M @ %r') AS Topic_Date, post_text, username FROM (phpbb_topics RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id) RIGHT JOIN phpbb_users ON topic_poster=(user_id WHERE forum_id=6) ORDER BY topic_time: 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 forum_id=6) ORDER BY topic_time' at line 1

This is MySQL 4.0.13 im using (well my host is using) ...

Something small causing this or am i gonna really have to rewrite the entire script? :(

Posted: Sun Jun 22, 2003 2:20 pm
by midtown
hmm ok -- i saw nothing wrong with the orignal code except that you didnt close the php script



?>

extra ;

Posted: Sun Jun 22, 2003 3:33 pm
by phpScott
I think you have one to many ; in your select

try

Code: Select all

$query = "SELECT topic_title, topic_id, FROM_UNIXTIME(topic_time,'%W the %D %M @ %r') AS Topic_Date, post_text, username FROM (phpbb_topics RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id) RIGHT JOIN phpbb_users ON topic_poster=(user_id WHERE forum_id=6) ORDER BY topic_time";
the extra ; was inside your final "
I don't think you need it

phpScott

Posted: Sun Jun 22, 2003 3:41 pm
by nielsene
OK I'm not a MySQL guy, but I see several possible problems from a normal SQL point of view: try the following

Code: Select all

SELECT topic_title, topic_id, 
      FROM_UNIXTIME(topic_time,'%W the %D %M @ %r') AS Topic_Date,
      post_text, username 
FROM phpbb_topics 
         RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id
         RIGHT JOIN phpbb_users        ON topic_poster=user_id 
WHERE forum_id=6 
ORDER BY topic_time;
You had some extra parentheses around the right joins. The first one should have been ok, but the second one had funny parenthesis around the join condition and the where clause.

Regarding the semi-colon phpScott noticed: you should always terminate your SQL statements (that means adding the semi-colon). This makes it harder for attackers to interject additional sql into the query, especially as MySQL disgards anything after the first unquoted semi-colon.

Posted: Sun Jun 22, 2003 8:28 pm
by Gappa
Hmm nope, not really working here either, its this MySQL 4.0.13, it just hates me, nothing is working! :(

Cross dependency found in OUTER JOIN. Examine your ON conditions...

gah!

Posted: Mon Jun 23, 2003 1:44 am
by volka

Code: Select all

SELECT topic_title, topic_id,
      FROM_UNIXTIME(topic_time,'%W the %D %M @ %r') AS Topic_Date,
      post_text
FROM phpbb_topics
RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id
JOIN phpbb_users
WHERE user_id=topic_poster AND forum_id=6
ORDER BY topic_time;
this one should work

Posted: Mon Jun 23, 2003 4:48 am
by Gappa
YOU THE MAAAAAAN!!

:D

works like a charm!

[edit]Actually... seems to be lacking 1 little thing!

Its not including the user name... hmmm[/edit]

Posted: Mon Jun 23, 2003 5:26 am
by volka
aye, the field somehow vanished, tztztz

Code: Select all

SELECT topic_title, topic_id,
      FROM_UNIXTIME(topic_time,'%W the %D %M @ %r') AS Topic_Date,
      post_text, username
FROM phpbb_topics
RIGHT JOIN phpbb_posts_text ON topic_first_post_id=post_id
JOIN phpbb_users
WHERE user_id=topic_poster AND forum_id=6
ORDER BY topic_time;
wasn't that difficult, was it? ;)

Posted: Mon Jun 23, 2003 9:25 am
by Gappa
1000 thanks :)

Hehe was gonna ask about changing the orde rof apperance, but i knew how to do that !!! :D thats right i knew how to do something haha, cheers again!