kate_rose Posted June 16, 2008 Share Posted June 16, 2008 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 https://forums.phpfreaks.com/topic/110474-solved-use-php-variable-in-mysql-query-syntax-error/ Share on other sites More sharing options...
hitman6003 Posted June 16, 2008 Share Posted June 16, 2008 you need to use the concatenation operator in your $query string... http://www.php.net/language.operators.string Link to comment https://forums.phpfreaks.com/topic/110474-solved-use-php-variable-in-mysql-query-syntax-error/#findComment-566756 Share on other sites More sharing options...
kate_rose Posted June 16, 2008 Author Share Posted June 16, 2008 Thanks, This is my first php script so please excuse my ignorance. Kate Link to comment https://forums.phpfreaks.com/topic/110474-solved-use-php-variable-in-mysql-query-syntax-error/#findComment-566768 Share on other sites More sharing options...
hitman6003 Posted June 16, 2008 Share Posted June 16, 2008 we all have to start somewhere... : ) Link to comment https://forums.phpfreaks.com/topic/110474-solved-use-php-variable-in-mysql-query-syntax-error/#findComment-566771 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.