Jump to content

PHP Parse Error


deslyxia

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/263907-php-parse-error/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/263907-php-parse-error/#findComment-1352431
Share on other sites

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.