Parse error

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Parse error

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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;";
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post 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? :(
midtown
Forum Newbie
Posts: 1
Joined: Sun Jun 22, 2003 2:20 pm

Post by midtown »

hmm ok -- i saw nothing wrong with the orignal code except that you didnt close the php script



?>
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

extra ;

Post 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
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post 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.
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post 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!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post 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]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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? ;)
Gappa
Forum Contributor
Posts: 119
Joined: Fri May 23, 2003 10:02 am

Post 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!
Post Reply