AncientSage Posted September 20, 2006 Share Posted September 20, 2006 Currently, I'm working on a forum script, using PEAR DBAL. The error I get is in the title, the code works fine in any other file, except this one. So I would guess it's code problems, the code:[code] $sql = "SELECT id, name FROM threads WHERE forum = " . '$id'; $result = $dbh->query($sql); $topics = array(); while($row = $result->fetchRow(DB_FETCHMODE_ASSOC)) { $topics[] = $row; } [/code]However, I don't see anything wrong with it...it's working on my index.php page, which is built the same, except this one has an if statement surrounding it.Possibly a query problem? Quote Link to comment Share on other sites More sharing options...
btherl Posted September 20, 2006 Share Posted September 20, 2006 Single quotes vs double quotes is important. It should be:[code]$sql = "SELECT id, name FROM threads WHERE forum = '$id'";[/code]What you had would literally put "$id", not the contents of the variable named id, into the query.You should also check if your result is valid before calling fetchRow .. it's actually an error, which is why it has no fetchRow method. Quote Link to comment Share on other sites More sharing options...
AncientSage Posted September 20, 2006 Author Share Posted September 20, 2006 Meh, I suck with the where clause. >_>Yeah, I intend to add some error checks here soon enough, hopefully I'll be able to comprehend the errors better then.Thanks for the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.