-2

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

My SQL query is below. It works fine on my local host, but when i upload to my linux server i get the above error. What is wrong?

this works on my local host, so why wouldn't it work on my server? is it a file path error? the MySQL database is identical, and i have a specific connect file for the server, that is different from the local host. my other database queries are working.

it is not an issue with the $id variable, because i tried testing it by replacing it with 1, and my error message was the same.

it is also not an issue with the connection to the database. this file has a number of other queries that are working properly.

    return (mysql_result(mysql_query("SELECT COUNT('id') FROM POSTS WHERE id=$id"),0)==0)?false:true;// this query works. because it doesnt have '' on the words posts/id
Community
  • 1
  • 1
arboles
  • 1,307
  • 4
  • 19
  • 39
  • 1
    Could you have made that code any more complicated? – John Conde Apr 18 '12 at 00:44
  • 1
    I'd bet you're not connected to the database. Make sure you can connect - are the credentials the same? Do you have the right database selected? – Ry- Apr 18 '12 at 00:45
  • @minitech: it could be a weird value in `$id` as well – zerkms Apr 18 '12 at 00:48
  • You must create a connection then submit it as an argument to mysql_result. In earlier versions this was optional. – Garvin Apr 18 '12 at 00:49
  • it is not an issue with the $id variable, because i tried testing it by replacing it with 1, and my error message was the same. this works on my local host, so why wouldnt it work on my server? is it a file path error? the mysql database is identical, and i have a specific connect file for the server, that is different from the local host – arboles Apr 18 '12 at 00:54
  • 1
    Does anyone bother searching for duplicates anymore? – Ignacio Vazquez-Abrams Apr 18 '12 at 00:56
  • What's `mysql_query`'s second parameter ? Give it a resource. – miqbal Apr 18 '12 at 00:59
  • 3
    Use the `mysql_error` function. It's there for a reason. Search for the error message you're getting, there are **tons** of identical questions. – deceze Apr 18 '12 at 01:16

2 Answers2

1

Error checking is a great thing:

function getResult() 
{
   try {
      $q = mysql_query( ... );

      if ($q === FALSE)
         throw new Exception(mysql_error(), mysql_errno());

      // Do stuff with the query results here.
   } catch(Exception $e) {
      // Do the error handling here
      //   Message is kept in $e->getMessage();
      //   MySQL specific error code is in $e->getCode();
   }
}
Linus Kleen
  • 32,634
  • 11
  • 88
  • 99
0

The Solution to this was that the query was searching the POST table. instead of the post table.

the table name is apparently case sensitive on my server, but not case sensitive on localhost.

arboles
  • 1,307
  • 4
  • 19
  • 39