Forum Moderators: coopster

Message Too Old, No Replies

SQL syntax error

         

ircsurfer

12:40 pm on May 5, 2008 (gmt 0)

10+ Year Member



i keep getting this error and for the life of me i cannot get past it.

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 ';") or die(mysql_error()); while($row = mysql_fetch_array($result)) { ' at line 2

The code block is as follows:

$sql = "SELECT * FROM (SELECT `company`, `license`, `contact`, `address1`, `address2`, `phone`, `fax`, `email`, `website` FROM `rcawcom_db`.`contractors`
ORDER BY `company`;\")
or die(mysql_error()); while(\$row = mysql_fetch_array(\$result)) { if (empty(\$row[website])) echo \"<font face='Arial' size='2' color='#000063'> <b>\$row[company]</b><br> </font>\"; else echo \"<a href=\\\"\$row[website]\\\" target=\\\"_blank\\\"><font face='Arial' size='2' color='#000063'><b>\$row[company]</b</a></font><br>\"; }) subq";

Any help is appreciated
Thanks

syber

1:26 pm on May 5, 2008 (gmt 0)

10+ Year Member



you are using a derived table (select on a select), so you need to alias the second select.

SELECT * FROM (SELECT `company`, `license`, `contact`, `address1`, `address2`, `phone`, `fax`, `email`, `website` FROM `rcawcom_db`.`contractors`
ORDER BY `company`;\") AS t2

ircsurfer

2:31 pm on May 5, 2008 (gmt 0)

10+ Year Member



That did not have any effect. It produces 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 ';") AS t2 or die(mysql_error()); while($row = mysql_fetch_array($result)) ' at line 2

coopster

2:56 pm on May 5, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, ircsurfer.

I would recommend setting up your query first in a variable and then execute the query and check for errors. You do not need the semicolon when constructing a query to be passed to MySQL via the PHP APIs so you should remove it. Then, you need to get your second quotation mark in at the close of your query statement. Finally, you execute the statement with the mysql_query [php.net] function.

$sql = "SELECT * FROM (SELECT `company`, `license`, `contact`, `address1`, `address2`, `phone`, `fax`, `email`, `website` FROM `rcawcom_db`.`contractors` ORDER BY `company`) AS t2";
$resultset = mysql_query($sql) or die(mysql_error());