473,396 Members | 1,599 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

syntax error on select stmt

I am getting this error when i run the php file and cant figure out why. everything seems to look fine. the error i get is:

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_Title' at line 3
here is my php code.

[PHP]<?php
$conn = mysql_connect ("localhost","root","")
or die (mysql_error ());
mysql_select_db ("stest",$conn) or die (mysql_error());

$display_block = "<h1>Categories</h1>
<p>select cat to see items.</p>";

$get_cats = "SELECT Cat_ID, cat_title, cat_description
FROM store_categories
ORDER BY cat_title";
$get_cat_res = mysql_query ($get_cats) or die (mysql_error());

if (mysql_num_rows($get_cat_res) < 1) {
$display_block = "<p><em>Sorry no cats to browse</em></p>";
} else {

while ($cats = mysql_fetch_array ($get_cat_res)) {
$cat_id = $cats [Cat_ID];
$cat_title = strtoupper (stripslashes ($cats[cat_title]));
$cat_desc = stripslashes ($cats [Cat_description]);

$display_block .= "<p><strong>
<a href=\"$_SERVER[PHP_SELF]?cat_id=$cat_id\">$cat_title</a></strong>
<br>$cat_desc</p>";

if ($_GET[Cat_ID] == $Cat_ID) {
$get_items = "SELECT Store_ID, Item_title, Item_Price FROM
Store_Items WHERE Cat_ID = $Cat_ID
ORDER BY Item_Title";
$get_item_results = mysql_query ($get_items) or die (mysql_error());

if (mysql_num_rows ($get_item_res) < 1 ) {
$display_block = "<p><em>Sorry no items in this category</em></p>";
} else {

$display_block .= "<ul>";

while ($items = mysql_fetch_array($get_item_res)) {
$item_id = $items[id];
$item_title = stripslashes($items[item_title]);
$item_price = $items[item_price];

$display_block .= "<li>
<a href=\"showitem.php?item_id=$item_id\">$item_title </a>
</strong> (\$$item_price)";

}

$display_block .= "<ul>";

}
}
}
}
?>
<html>
<head>
<title>My Categories</title>
</head>
<body>
<?php echo $display_block; ?>
</body>
</html>[/PHP]

thanks in advance for ur help.
Mar 2 '08 #1
1 1310
ronverdonk
4,258 Expert 4TB
When Cat_ID is a character type field, you must enclose the variable within quotes, as in
Expand|Select|Wrap|Line Numbers
  1. $get_items = "SELECT Store_ID, Item_title, Item_Price FROM
  2.               Store_Items WHERE Cat_ID = '$Cat_ID' 
  3.               ORDER BY Item_Title";
This is a MySQL problem, so I'll move this thread.

Ronald
Mar 3 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mohammed Mazid | last post by:
Can anyone please help me here? Basically I have modified the source code and understood it but when I update a record in the db using a JSP, it gives me an error "The flight you selected does...
7
by: Együd Csaba | last post by:
Hi, I've a problem with some of my stored procs. My config is: RH7.1, Postgres 7.3.2 I had converted a few fields of a few tables from one type to another and after this I made all the...
0
by: Aurelio Balgera | last post by:
I am experiencing a lot of problem with new new db2jcc driver. When I connect to the db2 V8.1 FP4 the db2diag.log (switched to diaglevel 4) show 2004-02-11-13.06.10.183779 Instance:db2prod ...
1
by: sid_mulpuru | last post by:
I am trying to read data from a DB2 Blob Data type Field (using wsad 5.1.0) using getBlob() which when executed gives an SQL Exception 2005-01-07 15:48:40,506 ERROR - Error in...
9
by: maas | last post by:
Hello I have a problem when coding the statement stmt.execute("insert into Member values ("+mname+" ,"+mail+","+tel+")"); where mname, mail,tel are variables which the user inputs them and...
1
by: maas | last post by:
hello i have a problem in the do while loop where the program will ask the user to enter yes and do an iteration, nut in my example it did not do?? here is the code import java.sql.*;...
9
by: Ratfish | last post by:
I'm getting a "2014:: Commands out of sync; you can't run this command now" error on a php page when I try to call a second stored procedure against a MySQL db. Does anyone know why I might be...
16
by: wizard | last post by:
Here is a piece of code below for writing and reading blobs in SQLITE database. I ' ve a problem to read from blob struct called 'Points' Any help would be appreciated Reagards Greg ...
3
by: phobia1 | last post by:
Hi once again. We have just changed our ISP and things that worked fine now do not, Obviously its in the differences of MYSQL and PHP versions. Have fixed most of the problems but this UPDATE...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.