Hello I'm having a problem with a query. I get the following error/warning:

PHP Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/mlhwebus/public_html/fairyfaun/sql/admin/send.php on line 385

Usually when this happens I have the program echo the query and then try it with PHPMyAdmin which will flag something wrong with the sql and I can get it fixed.

Today, however, I did the same thing and the query which follows in the () works fine in PHPMyAdmin.

(SELECT ltrque.id, dealer.email from ltrque, dealer where ltrque.dealid = dealer.id and ltrque.sendmeth = 'e' and ltrque.ltrsent = 'n' and ltrque.ltrtype = '2')

anyone have any ideas why php is flagging it as not a valid MySQL result?

    can you post your PHP code where you execute the query and then try to parse it?

      Here is the php that results in the query posted above. The query posted above is the result of an echo $query; inserted right before the $result statement.

      $query = "SELECT ltrque.id, dealer.email from ltrque, dealer where ltrque.dealid = dealer.id  and ltrque.sendmeth = 'e' and ltrque.ltrsent = 'n' and ltrque.ltrtype = '".$_GET['id']."'";
      	$result = mysql_query($query);
      	while($row = mysql_fetch_object($result))
      
        minifairy wrote:

        Usually when this happens I have the program echo the query and then try it with PHPMyAdmin

        So you never actually see what the error is and instead try to guess what's wrong? :p

        Try changing this:

        $result = mysql_query($query); 

        to this:

        $result = mysql_query($query) or die('MySQL error: ' . mysql_error() . "<hr>Query: $query");

        to get more debugging information. If you still can't find the error, paste the output of the above code.

          I can see the error in the error logs. It is posted in the first posting.

            don't know what I did but it seems to have gone away. Thanks.

              Also, forgot to mention...

              Your code is vulnerable to SQL injection attacks; user-supplied data should never be placed directly into SQL query strings. Instead, it must first be sanitized with a function such as [man]mysql_real_escape_string/man (or instead use an updated library w/ prepared statements, such as MySQLi or PDO). Note that in this case since I'm assuming the 'id' column is an integer, you could simply cast $_GET['id'] to an B[/B].

                Write a Reply...