Jump to content

supplied argument is not a valid MySQL result resource


Recommended Posts

Thanks for reading! I'm working on a site and it won't display my records from the database. I have a little filter system that did work, but now it doesn't. I get the following error message:

 

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /var/www/vhosts/60608.glrdmd.eu/httpdocs/jakesite/select3.php on line 26

 

 

Relevant code to the error is:

 

<?php 
include("connection.php");

if(isset($_POST['Graphic']) &&
   $_POST['Graphic'] == 'yes')
{
$result1 = "graphic";
}
if(isset($_POST['Interactive']) &&
   $_POST['Interactive'] == 'yes')
{
$result2 = "interactive";
}
if(isset($_POST['Websites']) &&
   $_POST['Websites'] == 'yes')
{
$result3 = "websites";
}
$order = $_POST['group1'];
$sql = ("SELECT * FROM 'jake_portfolio' WHERE CAT = '$result1' OR CAT = '$result2' OR CAT = '$result3' ORDER BY '$order' LIMIT 0, 4");
$result = mysql_query($sql);
$checked = "checked";
$row = mysql_fetch_array($result);
?>

 

Does anyone see what I am doing wrong here?

I have removed those quotes, I didn't have them there in the first place but I read somewhere that it might fix the problem?

 

Anyway I put this in:

 

$row = if(!mysql_fetch_array($result)){

echo mysql_error()};

 

And now I get the following error:

Parse error: syntax error, unexpected T_IF in /var/www/vhosts/60608.glrdmd.eu/httpdocs/jakesite/select3.php on line 26

This instead:

$result = mysql_query($sql) or die( "<br>Query string: $sql<br>Produced error: " . mysql_error() );

 

This would be for debugging only, BTW. On a live site, you would never want to echo the actual query string or MySQL error to the user.

Your suggested debugging solution provided me with this:

 

Query string: SELECT * FROM jake_portfolio WHERE CAT = OR CAT = OR CAT = ORDER BY LIMIT 0, 4

Produced error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OR CAT = OR CAT = ORDER BY LIMIT 0, 4' at line 1

 

So what is wrong with with my coding in that part? I have removed the ''s

All of your variables are empty. You'd need to post the form markup and any other relevant code so we can see what's up with it and offer suggestions . . .

The form is as follows:

 

<div id="filtermenu">
    <form action="select3.php" method="post">
      Search:
      <p>
        <input name="Graphic" type="checkbox" value="yes" <?PHP if($result1 == 'graphic'){print $checked ; }?>/>
        Graphic<br />
        <input name="Interactive" type="checkbox" value="yes"<?PHP if($result2 == 'interactive'){print $checked ; }?>/>
        Interactive<br />
        <input name="Websites" type="checkbox" value="yes" <?PHP if($result3 == 'websites'){print $checked ; }?>/>
        Websites</p>
      Sort by:
      <p>
        <input name="group1" type="radio" value="DATE DESC" <?PHP if($order == 'DATE DESC'){print $checked ; } elseif($order != 'DATE ASC' or 'VIEWS'){print $checked ;}?>/>
        Newest<br />
        <input name="group1" type="radio" value="DATE ASC" <?PHP if($order== 'DATE ASC'){print $checked ; }?>/>
        Oldest<br />
        <input name="group1" type="radio" value="VIEWS" <?PHP if($order == 'VIEWS'){print $checked ; }?>/>
        Most viewed</p>
      <input name="Search!" type="submit" value="Filter" id="button"/>
    </form>

 

thanks for taking your time for me by the way. :)

To stop the issue before submission, you need to make sure the form has been submitted before allowing the query to run. To do that, enclose everything after the include() in a conditional that checks whether the form has been sent. After that, see what errors are returned when the form is submitted, and post them along with the revised code.

 

<?php
include("connection.php");

if( strtolower($_SERVER['REQUEST_METHOD']) === 'post' ) {

// rest of code

}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.