How do I properly concatenate a variable in a SQL query? This is what I currently have:
PHP Code:$sql = 'SELECT image, name, description FROM phpbb_anime WHERE image = '.$animeimg.'';
| SitePoint Sponsor |
How do I properly concatenate a variable in a SQL query? This is what I currently have:
PHP Code:$sql = 'SELECT image, name, description FROM phpbb_anime WHERE image = '.$animeimg.'';


you need to make sure that you generate single quote delimiters for your image string
when it reaches mysql, it wants to look like this --of course, that's assuming image is a character column, not a numeric columnCode:WHERE image = 'foobar'
if it's a numeric column, and $animeimg is supposed to be an integer, then you should not generate quotes into the sql
you can tell if your statement is correct by echoing $sql before you execute it
Do I need I need to put the actual SQL statement in double or single quotations?


Well I can't particularly echo anything because I keep getting a SQL error


if you're getting an sql error, you must've executed the $sql string using mysql_query() or whatever the command in php is called
could you do the echo before that, please
also, it might help if i could see the error message
What is output by the echo?PHP Code:$sql = "SELECT image, name, description FROM phpbb_anime WHERE image = '$animeimg'";
echo $sql;
Community Team Advisor
Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator
When I echo that out it just outputs the code.


what happens if you submit the SELECT statement, with an appropriate value substituted for $animeimg, to mysql directly?
Bookmarks