SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Invalid query - On a valid query?

    Hi,

    I'll be quick. Have I been staring at the screen too long or is this error trying to tell me something:

    Array ( [Error] => Invalid Query :
    SELECT * FROM jw_ticket WHERE ticketID = '2' )
    1

    I'm not sure why I'm getting the error, but the code (below) is fine and the query is fine to me.

    PHP Code:
    $q "
            SELECT 
                *
            FROM 
                "
    .DB_PREFIX."ticket 
            WHERE ticketID = '"
    .$ticketID."'";
    $result $this->query($q);
            if(
    $this->num_rows($result) > 0){
                return 
    $this->fetch_assoc($result);
            } 
    Probably something stupid I can't see but any ideas?

    Cheers,
    Rhys

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Invalid query is a bit vague. Can you echo out the mysql error?

  3. #3
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Strange thing is I don't seem to get an error. My query function is:
    PHP Code:
    public function query($q){
            if(empty(
    $q)) $this->dbError('Empty MySQL Query.');
            if(
    $this->linkID == 0$this->connect();
            
    $temp = @mysql_query($q$this->linkID);
            if(!
    $temp$this->dbError('Invalid Query : '.mysql_error().'<br />'.$q);
            return 
    $temp;
        } 
    Maybe errors are off? I'll check...

  4. #4
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was just thinking, this function is used more than once and works for non-admin.

    PHP Code:
    function getTicketDetails($ticketID$admin false){
        
            
    $q "
            SELECT 
                *
            FROM 
                "
    .DB_PREFIX."ticket 
            WHERE ticketID = '"
    .$ticketID."'";
            
            if(
    $admin == false){
                
    $q .= " AND requesterID = '".$this->escape_string($this->getUserID())."'";
            }
            
            
    $result $this->query($q); 
    It works fine for non-admin. i.e. in the user part of the site it works fine.

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    So the question is: if it shows the db error, why is mysql_error() empty?
    Can you do a var_dump of $temp?

  6. #6
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK errors are on because a truly invalid query throws back an error such as Unknown column 'x' in 'where clause'

    So no error is given, but it won't run the query. Very irritating! Especially since the query is fine and working elsewhere.

  7. #7
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure, I get:

    resource(13) of type (mysql result) bool(true) resource(15) of type (mysql result) bool(false)

  8. #8
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    resource(13) of type (mysql result) bool(true)
    resource(15) of type (mysql result) bool(false)

    That boolean false is triggering the error. So one query is ok, the second isn't. Just to be sure, could you do an echo of $q right after the var_dump? I know the query is displayed by the dbError method, but still.

  9. #9
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    resource(15) of type (mysql result) SELECT * FROM jw_requester WHERE requesterEmail = '' AND requesterPassword = ''bool(false)

    Thanks guido. You just pointed it out to me. I thought I had covered all these things but clearly not.

    Cheers,
    Rhys

  10. #10
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK I've been chasing these queries for too long. Everytime I remove one to see if it is the problem, the new problem becomes and earlier query. Any ideas as to why it would error on an earlier and earlier query until you have none left?
    resource(13) of type (mysql result) SELECT * FROM jw_users WHERE userName = 'rhys' AND pass = '...' bool(false)

  11. #11
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Do an echo of mysql_error() as well. That way we can see all info about each query.

    It probably isn't the queries, but the connection.

  12. #12
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's the weird thing. There is no error.
    PHP Code:
    public function query($q){
            if(empty(
    $q)) $this->dbError('Empty MySQL Query.');
            if(
    $this->linkID == 0$this->connect();
            
    $temp = @mysql_query($q$this->linkID);
            
    var_dump($temp);
            echo 
    $q.'<br />';
            echo 
    mysql_error();
            if(!
    $temp$this->dbError('Invalid Query : '.mysql_error().'<br />'.$q);
            return 
    $temp;
        } 
    resource(13) of type (mysql result) SELECT * FROM jw_users WHERE userName = 'rhys' AND userPassword = '...'
    bool(true) UPDATE jw_users SET userLoginTimestamp = '1316512160' WHERE userID = '3'
    bool(false) SELECT * FROM jw_ticket WHERE ticketID = '1'
    Array ( [Error] => Invalid Query :
    SELECT * FROM jw_ticket WHERE ticketID = '1' )
    1

    I have no idea why but both mysql_error and errno are NULL.

  13. #13
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,401
    Mentioned
    147 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by TacMaf View Post
    I have no idea why but both mysql_error and errno are NULL.
    Beats me

  14. #14
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh oh I'm gonna have a hard time finding a solution to this then...

  15. #15
    SitePoint Guru TacMaf's Avatar
    Join Date
    Dec 2005
    Location
    Manchester, United Kingdom
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did it, just wrote a new identical function and renamed it. Figure that out??? I know I can't.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •