deslyxia Posted June 9, 2012 Share Posted June 9, 2012 I am getting the following code when executing a query: Parse error: syntax error, unexpected T_VARIABLE Below is the query it came from. //query db and build name array $qry="SELECT * FROM Patient WHERE LName LIKE "$q""; $result=mysql_query($qry); I know that the issue is coming from the double quotes around $q. If I switch them to single quotes I get no error... but I also get no results. I have looked up the difference between single and double quotes and I think i have it right. Single quotes use exactly what is in them ex. echo '$q'; would be $q Double quotes will evaluate the variable and use that ex. $q = 'php'; echo "$q"; would be php So this has me kind of lost as to what the issue is in my query. Quote Link to comment https://forums.phpfreaks.com/topic/263907-php-parse-error/ Share on other sites More sharing options...
PFMaBiSmAd Posted June 9, 2012 Share Posted June 9, 2012 The correct php and mysql syntax would be - $qry="SELECT * FROM Patient WHERE LName LIKE '$q'"; Using LIKE without any wildcard characters in the pattern is in most cases the same as using an equal comparison - $qry="SELECT * FROM Patient WHERE LName = '$q'"; What LName value are you trying to match and what value are you putting into the $q variable? Quote Link to comment https://forums.phpfreaks.com/topic/263907-php-parse-error/#findComment-1352431 Share on other sites More sharing options...
deslyxia Posted June 9, 2012 Author Share Posted June 9, 2012 In my Table I have hundreds of LName. $q comes from a user input field on the main page. The purpose here is that every time a user types a letter in the field this query selects all rows from my table that contain the user input string. Quote Link to comment https://forums.phpfreaks.com/topic/263907-php-parse-error/#findComment-1352432 Share on other sites More sharing options...
PFMaBiSmAd Posted June 9, 2012 Share Posted June 9, 2012 I'll assume you mean you want to find names that start with the entered string. You would use a trailing % wildcard to match everything that starts with the entered string - $qry="SELECT * FROM Patient WHERE LName LIKE '$q%'"; Quote Link to comment https://forums.phpfreaks.com/topic/263907-php-parse-error/#findComment-1352433 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.