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);
}
?>

Link to comment
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.