captain_scarlet87 Posted March 26, 2010 Share Posted March 26, 2010 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 https://forums.phpfreaks.com/topic/196594-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/ Share on other sites More sharing options...
cags Posted March 26, 2010 Share Posted March 26, 2010 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 https://forums.phpfreaks.com/topic/196594-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-1032195 Share on other sites More sharing options...
captain_scarlet87 Posted March 26, 2010 Author Share Posted March 26, 2010 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? Link to comment https://forums.phpfreaks.com/topic/196594-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-1032256 Share on other sites More sharing options...
Irap Posted March 26, 2010 Share Posted March 26, 2010 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 https://forums.phpfreaks.com/topic/196594-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-1032267 Share on other sites More sharing options...
Kieran Menor Posted March 26, 2010 Share Posted March 26, 2010 SELECT * FROM `uploaded_instructions` WHERE `title`= '{$file_name_no_ext}' You should probably include single quotes around the value. Link to comment https://forums.phpfreaks.com/topic/196594-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-1032270 Share on other sites More sharing options...
captain_scarlet87 Posted March 26, 2010 Author Share Posted March 26, 2010 Cheers Boom.dk, it worked a treat! Link to comment https://forums.phpfreaks.com/topic/196594-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-1032291 Share on other sites More sharing options...
captain_scarlet87 Posted March 26, 2010 Author Share Posted March 26, 2010 Sorry thanks aswell Irap Link to comment https://forums.phpfreaks.com/topic/196594-warning-mysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result-reso/#findComment-1032294 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.