SQL Syntax 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
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

SQL Syntax error

Post by ljCharlie »

Will anyone tell me what's wrong with this?

In my PHP page, I have the following code.

$query_rsFamilyDtls = sprintf("SELECT * FROM children WHERE familyID = %s AND %s ORDER BY %s ASC", $colname_rsFamilyDtls,$NXTFilter_rsFamilyDtls,$NXTSort_rsFamilyDtls);

The query from above generated the query below:

SELECT * FROM children WHERE familyID = 1 AND 1=1 ORDER BY fstName ASC

In Mozilla Firefox, it is fine. However in MS IE, I received this error:

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 'ASC' at line 1
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Where does $NXTSort_rsFamilyDtls come from?
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


That comes from here:

Code: Select all

$NXTSort_rsFamilyDtls = ".fstName";
if (isset($_SESSION['sorter_tso_listrsFamilyDtls1'])) {
  $NXTSort_rsFamilyDtls = $_SESSION['sorter_tso_listrsFamilyDtls1'];
}

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

I did an echo of $query_rsFamilyDtls and I got this line,

SELECT * FROM children WHERE familyID = 1 AND 1=1 ORDER BY fstName ASC

on the Firefox browser. I did this

$query_rsFamilyDtls = sprintf("SELECT * FROM children WHERE familyID = %s AND %s", $colname_rsFamilyDtls,$NXTFilter_rsFamilyDtls);

then it works fine in both browser but I want to have the sort.
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

feyd, thank you so much for your help. I got it fixed now. The problem lies in this code, ".fstName";

All I had to do is delete the period before the "f" and it works. Not sure why the period cause a problem in MS IE and not in Mozilla browser.
Post Reply