hikaru_kagi — 2012-05-04T20:56:31-04:00 — #1
How do I properly concatenate a variable in a SQL query? This is what I currently have:
$sql = 'SELECT image, name, description FROM phpbb_anime WHERE image = '.$animeimg.'';
r937 — 2012-05-04T21:07:33-04:00 — #2
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 --
WHERE image = 'foobar'
of course, that's assuming image is a character column, not a numeric column
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
hikaru_kagi — 2012-05-04T21:48:52-04:00 — #3
Do I need I need to put the actual SQL statement in double or single quotations?
r937 — 2012-05-04T22:25:04-04:00 — #4
can't help you with that, sorry, i don't do php
what did the echo of $sql produce?
hikaru_kagi — 2012-05-04T22:51:26-04:00 — #5
Well I can't particularly echo anything because I keep getting a SQL error
r937 — 2012-05-05T02:21:11-04:00 — #6
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
spacephoenix — 2012-05-05T03:20:43-04:00 — #7
$sql = "SELECT image, name, description FROM phpbb_anime WHERE image = '$animeimg'";
What is output by the echo?
hikaru_kagi — 2012-05-05T04:08:48-04:00 — #8
When I echo that out it just outputs the code.
r937 — 2012-05-05T06:56:36-04:00 — #9
what happens if you submit the SELECT statement, with an appropriate value substituted for $animeimg, to mysql directly?