GFOnyX Posted September 23, 2013 Share Posted September 23, 2013 Hi. I am having trouble embedding a swf file from a database on a php page. I know how to embed a swf file using just php with the help of swfobject.js but I am having trouble being able to actually show the file from a db. I am not storing the actual file on the database but the path to the flash file (eg games/flashgame1.swf) I am properly connected to the db so there is no problem there. The table is called games and has two columns for now: id | path Here is my code: <?php require_once('config.php'); if (!session_id()) session_start(); ?> <!DOCTYPE html> <html> <head> <meta content="text/html; charset=UTF-8" http-equiv="content-type"> <meta name="author" content="Onyx"> <link rel="stylesheet" type="text/css" href="<?php echo HTTP_STYLE;?>layout.css" /> <link href="<?php echo HTTP_IMAGES;?>favicon.ico" rel="icon" type="image/x-icon" /> </head> <body> <div id="wrapper2"> <div id="container"> <?php $result = mysql_query("SELECT * FROM games"); while($row = mysql_fetch_array($result)) { $path = $row['1']; $id = $row['0']; $width = "546"; $height = "431"; $version = "9.0.0"; } echo "<script type=text/javascript src=swfobject.js></script>"; echo "<script type=text/javascript>"; echo "swfobject.embedSWF('$path','$id', '$width', '$height', '$version')";echo "</script>"; ?> </div> </div> </body> </html> Any ideas what i am doing wrong? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 23, 2013 Share Posted September 23, 2013 your code for getting the path out of the database looks fine to me. What is the following line outputting? echo "swfobject.embedSWF('$path','$id', '$width', '$height', '$version')";echo "</script>"; Is this outputting the correct JavaScript syntax? if it is you need to make sure $path is pointing to correct location of where your .swf files are located. Quote Link to comment Share on other sites More sharing options...
GFOnyX Posted September 23, 2013 Author Share Posted September 23, 2013 The page does not output anything currently besides some css styling (footer,header etc) I created another column called image and i can properly echo out the image so i am connected to the DB and the path to the swf file is correct. I have checked many times in case it was that. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 23, 2013 Share Posted September 23, 2013 Ok sounds like PHP is failing due to an error. Add the following two lines before require_once('config.php'); error_reporting(E_ALL); ini_set('display_errors', true); What errors are shown? Quote Link to comment Share on other sites More sharing options...
GFOnyX Posted September 23, 2013 Author Share Posted September 23, 2013 I changed mysql_fetch_array to mysql_fetch_assoc in case it makes a difference but nothing changed.The error is as following Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in the line that has while($row = mysql_fetch_assoc($result)) Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in the line that has while($row = mysql_fetch_array($result)) Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 23, 2013 Share Posted September 23, 2013 (edited) That error usually indicates your query is failing due to an error or is returning an empty result. To see if there is an error from your query. Chang the mysql_query line to $result = mysql_query("SELECT * FROM games") or die('Query Error: ', mysql_error()); This should print out an error if the query is failing. Edited September 23, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
GFOnyX Posted September 23, 2013 Author Share Posted September 23, 2013 (edited) I am getting Parse error: syntax error, unexpected ',' in C:\xampp\htdocs\kinderlearn\game2.php on line 27 something wrong with the syntax of the above line. The query runs fine if i execute it on MySQL via PHPmyadmin. It returns the correct results. I don't see how it can be wrong.It is like the simplest query Edited September 23, 2013 by GFOnyX Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 23, 2013 Share Posted September 23, 2013 My bad the code I gave you had an error. It should be $result = mysql_query("SELECT * FROM games") or die('Query Error: '. mysql_error()); Quote Link to comment Share on other sites More sharing options...
GFOnyX Posted September 23, 2013 Author Share Posted September 23, 2013 (edited) Sorry Ch0cu3r i am stupid. When i was executing your requests i was hiting the link as http://localhost/project/game2.php which of course would return an error since i am calling every page from index.php which contains the dbconnect file. When i saw the image i had the link as http://localhost/project/index.php?page=game2.php which is correct. Sorry for the trouble. The problem however remains. No error messages but still can not see the swf file... Here is my latest code <?php error_reporting(E_ALL); ini_set('display_errors', true); require_once('config.php'); if (!session_id()) session_start(); ?> <!DOCTYPE html> <html> <head> <meta content="text/html; charset=UTF-8" http-equiv="content-type"> <meta name="author" content="Onyx"> <link rel="stylesheet" type="text/css" href="<?php echo HTTP_STYLE;?>layout.css" /> <link href="<?php echo HTTP_IMAGES;?>favicon.ico" rel="icon" type="image/x-icon" /> </head> <body> <div id="wrapper2"> <div id="container"> <?php $path=""; $id=""; $width=""; $height=""; $version=""; $image=""; $result = mysql_query("SELECT * FROM games") or die('Query Error: '. mysql_error()); while ($row = mysql_fetch_assoc($result)) { $path = $row['path']; $id = $row['id']; $width = "546"; $height = "431"; $version = "9.0.0"; $image = $row['image']; } echo "<script src='swfobject.js'></script>"; echo "swfobject.embedSWF(" . $path . ", " . $id . ", " . $width . ", " . $height . ", " . $version . ")"; echo "<img src=$image>"; ?> </div> </div> </body> </html> The above outputs: swfobject.embedSWF(Start_Quiz_App.swf, 1, 546, 431, 9.0.0) and the image i have. Edited September 23, 2013 by GFOnyX Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 23, 2013 Share Posted September 23, 2013 Ok so your code PHP is working correctly as it a is outputting the Javascript code within your while loop. The next problem to tackle then is making sure your Javasript does not have any errors If you are using the latest version of IE, Firefox, Chrome etc you should to access the Developer Tools pain by pressing F12. Go to the console tab and refresh your page (using F5). Does the console log any errors? Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted September 23, 2013 Share Posted September 23, 2013 the parameters you are putting into the swfobject.embedSWF() statement need the quotes around them (at least the non-numerical ones). you removed the quotes in the last posted code, but had them up to that point. Quote Link to comment Share on other sites More sharing options...
.josh Posted September 23, 2013 Share Posted September 23, 2013 echo "<script src='swfobject.js'></script>"; echo "swfobject.embedSWF(" . $path . ", " . $id . ", " . $width . ", " . $height . ", " . $version . ")"; echo "<img src=$image>";This isn't going to output correct javascript syntax. Firstly you didn't wrap the js in script tags. 2nd, you didn't wrap your values in quotes. The number arguments might work without them but the path certainly won't. Quote Link to comment Share on other sites More sharing options...
GFOnyX Posted September 23, 2013 Author Share Posted September 23, 2013 These are the errors i am getting.I should say that one the same site on a different page i can display swf files just fine but they are not stored in the DB.I call them manually. It is when i try to call them from the DB that they do not display. HTML1502: Unexpected DOCTYPE. Only one DOCTYPE is allowed and it must occur before any elements. index.php, line 64 character 1 HTML1503: Unexpected start tag. index.php, line 65 character 1 HTML1512: Unmatched end tag. index.php, line 70 character 1 HTML1514: Extra "<body>" tag found. Only one "<body>" tag should exist per document. index.php, line 72 character 1 HTML1521: Unexpected "</body>" or end of file. All open elements should be closed before the end of the document. index.php, line 81 character 1 FB.getLoginStatus() called before calling FB.init(). Quote Link to comment Share on other sites More sharing options...
.josh Posted September 23, 2013 Share Posted September 23, 2013 and you don't see swfobject.embedSWF(Start_Quiz_App.swf, 1, 546, 431, 9.0.0) being output as plain text on your page?? Quote Link to comment Share on other sites More sharing options...
GFOnyX Posted September 23, 2013 Author Share Posted September 23, 2013 and you don't see swfobject.embedSWF(Start_Quiz_App.swf, 1, 546, 431, 9.0.0) being output as plain text on your page?? Yes i see that. I mention it at post #9 Quote Link to comment Share on other sites More sharing options...
.josh Posted September 23, 2013 Share Posted September 23, 2013 okay so Ch0cu3r just had you do that so you could verify the output. You need to change it back to correct javascript syntax and then see if you get any javascript errors. Change it back to how you had it originally: echo "<script type='text/javascript' src='swfobject.js'></script>"; echo "<script type='text/javascript'>"; echo "swfobject.embedSWF('$path','$id', '$width', '$height', '$version')";echo "</script>"; Then look to see if the js console is giving any errors. Also, it looks like your $path is just outputting "Start_Quiz_App.swf" is your .swf file really located the same directory as the script? Quote Link to comment Share on other sites More sharing options...
GFOnyX Posted September 23, 2013 Author Share Posted September 23, 2013 (edited) First of all,thank you all for helping me. I replaced the code as Josh said but now i get no output at all at the page. I went to firefox and checked the JS under console and shows these two things. I don't know if these are what you mean... [18:57:32.342] Use of getUserData() or setUserData() is deprecated. Use WeakMap or element.dataset instead. @ resource://gre/modules/XPIProvider.jsm -> jar:file:///C:/Users/Alexander/AppData/Roaming/Mozilla/Firefox/Profiles/m5buocf4.default/extensions/%7Bd10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d%7D.xpi!/bootstrap.js -> jar:file:///C:/Users/Alexander/AppData/Roaming/Mozilla/Firefox/Profiles/m5buocf4.default/extensions/%7Bd10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d%7D.xpi!/lib/requestNotifier.js:64[18:57:32.497] Use of getPreventDefault() is deprecated. Use defaultPrevented instead. @ chrome://flashblock/content/flashblock.xml:119 Yes the swf file is located in the same dir as the script which is the root of the site. Edited September 23, 2013 by GFOnyX Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted September 23, 2013 Solution Share Posted September 23, 2013 (edited) You are going to http://localhost/ to run your php scripts. You can't directly access php scripts from file:// protocol. Those errors are coming from a browser extension you have installed called flashblock. This could be interfering, try disabling it. Any way ou may also want to read this part of the documentation https://code.google.com/p/swfobject/wiki/documentation#STEP_3:_Embed_your_SWF_with (I assume that is the js library you're using) The id (secound) parameter for swfobject needs to be the name of the html element where you want the swf file to be displayed. Having just that line of javascript isn't going to display the swf file. You may need to add this line to your while loop echo '<div id="'.$id.'"><p>Alternative content</p></div>'; Edited September 23, 2013 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
GFOnyX Posted September 23, 2013 Author Share Posted September 23, 2013 You are going to http://localhost/ to run your php scripts. You can't directly access php scripts from file:// protocol. Those errors are coming from a browser extension you have installed called flashblock. This could be interfering, try disabling it. Any way ou may also want to read this part of the documentation https://code.google.com/p/swfobject/wiki/documentation#STEP_3:_Embed_your_SWF_with (I assume that is the js library you're using) The id (secound) parameter for swfobject needs to be the name of the html element where you want the swf file to be displayed. Having just that line of javascript isn't going to display the swf file. You may need to add this line to your while loop echo '<div id="'.$id.'"><p>Alternative content</p></div>'; And that was the miracle line that was missing! I for sure will study the link though. I can not thank you enough for taking the time and helping me out. All of you guys, thank you very much!!! Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 23, 2013 Share Posted September 23, 2013 he, no problem glad to help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.