Problem with query...

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
User avatar
partiallynothing
Forum Commoner
Posts: 61
Joined: Fri Nov 21, 2003 5:02 pm
Location: connecticut, usa

Problem with query...

Post by partiallynothing »

I don't know why this code doesn;t work!

Code: Select all

<?php
echo "<BR>";
$query = "SELECT id, name, desc, url FROM c_forums ORDER BY id DESC";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
	echo "<b>{$row['id']}. {$row['name']}</b> - <a href="{$row['url']}" target="_blank">{$row['name']}</a><BR>{$row['desc']}<BR><BR>"; }
?>
With the above, I get this error"You have an error in your SQL syntax near 'desc, url FROM c_forums ORDER BY id DESC' at line 1". Thanks for any help!
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

are you sure all of those tables/fields exist? (did you enter the correct names?)
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

desc is reserved word (it's used in ORDER BY clause).
Post Reply