mishasoni Posted October 10, 2008 Share Posted October 10, 2008 PHP newbie here - I am getting the following sql syntax 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 'begins with B ORDER BY NameLast ASC LIMIT 0, 30' at line 1" I believe this error is referring to the below section of code: if (isset($_GET['firstletter'])) { $firstletter = $_GET['firstletter']; } $query_rsParticipants = "SELECT * FROM Contacts WHERE ContactType = 'Scientist' AND ContactID_pk <> 0 AND NameLast begins with $firstletter ORDER BY NameLast ASC"; Can anyone tell me what the error is? Link to comment https://forums.phpfreaks.com/topic/127791-syntax-error-help/ Share on other sites More sharing options...
revraz Posted October 10, 2008 Share Posted October 10, 2008 The error is "begins with" Try LIKE instead. Link to comment https://forums.phpfreaks.com/topic/127791-syntax-error-help/#findComment-661496 Share on other sites More sharing options...
mishasoni Posted October 10, 2008 Author Share Posted October 10, 2008 I should clarify what I am trying to do. $firstletter = either A, B, C, D...etc. I want to filter records alphabetically by NameLast, so that, for example, only last names beginning with "B" are shown. Thanks. Link to comment https://forums.phpfreaks.com/topic/127791-syntax-error-help/#findComment-661533 Share on other sites More sharing options...
DarkWater Posted October 10, 2008 Share Posted October 10, 2008 $query_rsParticipants = "SELECT * FROM Contacts WHERE ContactType = 'Scientist' AND ContactID_pk <> 0 AND NameLast LIKE '$firstletter%' ORDER BY NameLast ASC"; That should be your query. Link to comment https://forums.phpfreaks.com/topic/127791-syntax-error-help/#findComment-661535 Share on other sites More sharing options...
mishasoni Posted October 10, 2008 Author Share Posted October 10, 2008 Thank you! Link to comment https://forums.phpfreaks.com/topic/127791-syntax-error-help/#findComment-662043 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.