will_1990 Posted March 5, 2009 Share Posted March 5, 2009 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!! Quote Link to comment https://forums.phpfreaks.com/topic/148016-solved-query-error-correct-use-of-quotes-issue/ Share on other sites More sharing options...
corbin Posted March 5, 2009 Share Posted March 5, 2009 " 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. Quote Link to comment https://forums.phpfreaks.com/topic/148016-solved-query-error-correct-use-of-quotes-issue/#findComment-776904 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.