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!!

 

 

Link to comment
Share on other sites

" 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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.