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.


$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

That’s the weird thing. There is no error.


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.

Invalid query is a bit vague. Can you echo out the mysql error?

Strange thing is I don’t seem to get an error. My query function is:

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…

I was just thinking, this function is used more than once and works for non-admin.


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.

So the question is: if it shows the db error, why is mysql_error() empty?
Can you do a var_dump of $temp?

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.

Sure, I get:

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

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.

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

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)

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.

Beats me :frowning:

Oh oh :eek: I’m gonna have a hard time finding a solution to this then…

Did it, just wrote a new identical function and renamed it. Figure that out??? I know I can’t. :rolleyes: