Jump to content

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

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.