Jump to content

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result reso


captain_scarlet87

Recommended Posts

Can anyone explain why I am getting this error:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\html\video_player.php on line 35

 

The aim of the code is to display a video passed from another page which works perfectly well.

 

I've recently added the table at the end which should display a link when the video name (replacing the underscores between words with spaces and removing the file extension) matches the text in a field call title in a table.

 

Please help. Thank you.

 

<?php
$video = $_GET['video'];
$file_name = str_replace('_',' ',$video);
$file_name_no_ext = substr($file_name, 0, strrpos($file_name, '.'));
?>

<html>
<head>
    <title>Videos</title>
    <script src="flowplayer/example/flowplayer-3.1.4.min.js"></script>
</head>
<body>

<a
    href="includes/videos/<?php echo($video); ?>"
    style="display:block;width:425px;height:300px;"
    id="player">
</a>

<script language="JavaScript">
    flowplayer("player", "flowplayer/flowplayer-3.1.5.swf");
</script>

<table>
  <tr>
    <td align="center">View Instructions</td>
  </tr>
  <tr>
    <td>
      <table border="1">
      <?php
      require_once ('../mysql_connect.php'); // Connect to the database.
      $order = "SELECT * FROM uploaded_instructions WHERE title=$file_name_no_ext";
      $result = mysql_query($order);
      while ($row=mysql_fetch_array($result)){
        echo ("<a href=view_instructions.php?instructions_id=$row[instructions_id]> $row[title] </a><br />");} // <tr><td>$row[title]</td>
      ?>
      </table>
    </td>
   </tr>
</table>

</body>
</html>

Link to comment
Share on other sites

You are getting that error because mysql_query is returning FALSE because you have an error with your query. On the line directly below where you call mysql_query add...

 

echo mysql_error();

...to find out what that error is. But I suspect it's because you don't have single quotes around the $file_name_no_ext variable in your query. Assuming this is a string it will require them.

Link to comment
Share on other sites

Try replacing your query with:

 

SELECT * FROM `uploaded_instructions` WHERE `title`={$file_name_no_ext}

 

`table_name` is good to use as you might end up typing SQL keywords, invalidating the query... "title" could be one.

 

I like to add {} to make PHP parse the $file_name_no_ext properly (and not use it as raw text). I like to think that should be the standard.

 

If that doesn't work, make sure the tables "uploaded_instructions" and "title" actually exist within your table. I've found that I often get the table names muddled.

Link to comment
Share on other sites

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.