Jump to content

*RESOLCED* Why do i get this error?


JJohnsenDK

Recommended Posts

Hey

I looked through this a thoundens times but i just cant see what the error is.

I get this error:
[i]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 'order by item_color' at line 1[/i]

And im using this code
[code]
//Hent farver på tøjet
$get_color = "SELECT item_color FROM store_item_color WHERE item_id = $item_id ORDER BY item_color";
$get_color_res = mysql_query($get_color) or die(mysql_error());

if (mysql_num_rows($get_color_res) > 0){
$display_block .= "<p><strong>Disse farver er tilgængelig:</strong></p>";

while($colors = mysql_fetch_array($get_color_res)){
$item_color = $colors['item_color'];

$display_block .="$item_color<br>";
}
}
[/code]

Anyone who can find the error?
Link to comment
https://forums.phpfreaks.com/topic/30669-resolced-why-do-i-get-this-error/
Share on other sites

You've missed out some single quotes in your query, try this:
[code]SELECT `item_color` FROM `store_item_color` WHERE `item_id` = '$item_id' ORDER BY `item_color`[/code]
I've enclosed your field/table names with backticks too, this is generally considered good practice.

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.