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>

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.

This is the error I now get:

 

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 'video' at line 1

 

Can't see what's up, the video in the player is working fine.

 

Any advice?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.