0

I have a mysql query where i want to only return records that match a userID and I want them ordered by entryID. Here is my code:

function ListAllEntries($dbh, $user)
{
    try {

     $query = 'SELECT * ' .
               'FROM entries ' .
               'WHERE userID = :uid' .
               'ORDER BY entryID';

        $stmt = $dbh->prepare($query);

        $stmt->bindParam(':uid', $user);

        $stmt->execute();

        $entrydata = $stmt->fetchAll(PDO::FETCH_OBJ);

        $stmt = null;

        return $entrydata;
    }
    catch(PDOException $e)
    {
        die ('PDO error getting users pictures": ' . $e->getMessage() );
    }
}

When I run this function I get the following error:

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in

which is followed up by the filename and error location which I obviously won't put here.

I'm not exactly sure what I'm doing wrong here. Any suggestions would be greatly appreciated. Thanks!

P.S. let me know if there is any other details that you need to know.

Mr Shantastic
  • 510
  • 1
  • 7
  • 16
  • Oh, well you did bind `:uid`. However there's no space between that parameter and `ORDER BY`, so the resulting query would look like `… = :uidORDER BY …` - which is why it is mistaken as omitted parameter. – mario Sep 23 '15 at 01:29
  • Yes, i'm sorry, i failed to mention that I did see that other question. And yes, the problem was with the fact that I was missing that space... i feel so dumb right now for not noticing that before posting the question... LOL. Thanks though! It works now... – Mr Shantastic Sep 23 '15 at 02:03

0 Answers0