Jump to content

[SOLVED] use php variable in mysql query - syntax error??


kate_rose

Recommended Posts

I have found exactly this search but the problem wasn't quite the same in that they were using the variable as the value to test against instead of the variable itself.  I just can't seem to figure out how to make this work.  Not sure that totally made sense but you will see in my code. 

 

It is the query statement that is giving me the error.  If I replace the $show_this with actual values contained in the mysql table it works just fine.  I have checked to make sure $show_this contains data which is a valid column in my database.

 

The error is: Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\Guana_Plant_Key\browse.php on line 28

 

<?php
foreach ($to_show as $show_this) {
// load links or jpeg names from guana_plants db into $picmysql
$query = "SELECT "$show_this" FROM guana_plants WHERE "$show_this" <> 'none' AND "$show_this" <> '"$show_this"'";
$result = mysql_query($query);
}
?>

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.