Page 1 of 1
Simple Query
Posted: Wed Sep 28, 2005 1:54 pm
by ethoemmes
Can anyone spot my error?
Code: Select all
$query = 'SELECT ImageID, BookID, ImageName, ImageLocation FROM tblImage
WHERE BookID = $BookID';
Is returning
Could not read data because Unknown column '$BookID' in 'where clause'
TIA
Edgar
Posted: Wed Sep 28, 2005 2:00 pm
by shiznatix
becuase it is in single quotes php wont parse the variable. try this
Code: Select all
$query = "SELECT ImageID, BookID, ImageName, ImageLocation FROM tblImage
WHERE BookID = $BookID";
SOLVED
Posted: Wed Sep 28, 2005 2:37 pm
by ethoemmes
Thanks.

Re: Simple Query
Posted: Thu Sep 29, 2005 4:57 am
by omega-systems
the Better to use single quotes for parameters in where part.
Code: Select all
$query = "SELECT ImageID, BookID, ImageName, ImageLocation FROM tblImage
WHERE BookID = '$BookID'";
It'll prevent most of problems with security. For instance for this case (i guess, BookID is 'integer'), you'll have problems with $BookID='a2'. In statement without quote we will get error, in my example we will not get any row only

.
Regards,
Michael.
Project Manager
Omega Systems Ltd
Email:
info@omega-systems.biz
ICQ: 264962449
MSN:
omega-systems@hotmail.com
AIM: OmegaSys Ltd