Jump to content

[SOLVED] query error - correct use of quotes issue


will_1990

Recommended Posts

This is the query that does not work but works in php with static data instead of variables:

 

$sql = "SELECT bt.BtId, bt.BtName, BookCopy.BcId, PubName, AuthorId, AuthorName'
        . ' FROM BookTitle AS bt'
        . ' CROSS JOIN BookCopy USING (BtId)'
        . ' CROSS JOIN Loan USING (BcId)'
        . ' CROSS JOIN Publisher USING (PubId)'
        . ' CROSS JOIN Authorship USING (BtId)'
        . ' CROSS JOIN Author USING (AuthorId)'
        . ' WHERE'
        . ' Loan.DateBack IS NOT NULL'
        . ' AND'
        . ' bt.BtName LIKE \'%Harry%\' AND Author.AuthorName LIKE \'%row%\' LIMIT 0, 30 ';
$result = mysql_query($sql) or die(mysql_error());

 

 

i have swapped this for these variables:

 

. ' bt.BtName LIKE \'%$bn%\' AND Author.AuthorName LIKE \'%$an%\' LIMIT 0, 30 ';

 

However apparantly its not parsed without double quotes - so i tried this:

 

$sql = "SELECT bt.BtId, bt.BtName, BookCopy.BcId, PubName, AuthorId, AuthorName'
        . ' FROM BookTitle AS bt'
        . ' CROSS JOIN BookCopy USING (BtId)'
        . ' CROSS JOIN Loan USING (BcId)'
        . ' CROSS JOIN Publisher USING (PubId)'
        . ' CROSS JOIN Authorship USING (BtId)'
        . ' CROSS JOIN Author USING (AuthorId)'
        . ' WHERE'
        . ' Loan.DateBack IS NOT NULL'
        . ' AND'
        . ' bt.BtName LIKE \'%$bn%\' AND Author.AuthorName LIKE \'%$an%\' LIMIT 0, 30 ";
$result = mysql_query($sql) or die(mysql_error());

 

but now i get 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 '' . ' CROSS JOIN BookCopy USING (BtId)' . ' CROSS JOIN Loan USIN' at line 1

 

I have no idea what i need to do to make this work!!! Any advice/help that gets me a little further will be greatly appreciated!!

 

 

" and ' are not interchangable.

 

 

All of the ' . ' that you have, are being literally put into the string.

 

 

 

Don't take this the wrong way, but perhaps you should read a tutorial about string concatentation in PHP.

 

 

 

\' can be ' when enclosed in "" by the way.

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.