Page 1 of 1

SQL Syntax error

Posted: Fri Apr 14, 2006 1:55 pm
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

Posted: Fri Apr 14, 2006 2:04 pm
by feyd
Where does $NXTSort_rsFamilyDtls come from?

Posted: Fri Apr 14, 2006 2:06 pm
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]

Posted: Fri Apr 14, 2006 2:09 pm
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.

Posted: Fri Apr 14, 2006 2:16 pm
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.