I want to insert a PHP variable’s value within select query in PHP-MySQL:
$result = @mysql_query(‘SELECT * FROM table where var1=”;’);
There is a syntax error. I’m sure it would be because of the inappropriate use of quotes. Please answer the right coding. Thanks



Hi There,
The issue is that you are opening php tags within php tags, this is invalid.
mysql_query() requires a string parameter.
$result = @mysql_query(‘SELECT * FROM table where var1=”fred”;’);
Would do the job, because I started the string with a single quote, I can use double quotes within the string without problems. I will now give you 2 ways to insert a variable into a string.
$result = @mysql_query(‘SELECT * FROM table where var1=”‘.$value1.’”;’);
$result = @mysql_query(“SELECT * FROM table where var1=’$value1′”;’);
Notice the use of single quotes in the first example and double in the second. Within double quotes, you can insert variables into the string without using concatenation (.).
capitalize query functions, such as where, etc… variables are only capitalized if the variable is defined as such. Though, it doesn’t matter if the server ignores capitalization. I cant tell you much else from there.