Wonka Wonka - 5 months ago 20
MySQL Question

INSERT Flash Object Into MySql with PHP

I'm breaking my head over this.

I'm trying to insert embeddable video code, such as youtube/viddler/etc.. which all start with the object tag:

<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/Ahg6qcgoay4?fs=1&amp;hl=en_US"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/Ahg6qcgoay4?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object>

into MySQL with PHP. I've looked all over the internet and there was nothing solid to make that happen. Does anyone know how to INSERT that code successfully to the database as the value for $video?

UPDATE: I figured out how to store it but now, I'm trying to call it in php, but only get the text value back, basically, the entire embed code as text is displayed instead of the video itself. Here is my display code which shows text. How can I make it show the actual video instead?

//assuming a connection to the database exists
$sql = "SELECT * FROM table";
$result = mysql_query( $sql );
while( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ) {
$html = array(); //create an array of html formated values.
$html['video'] = nl2br( stripslashes( htmlentities( $row['video'], ENT_QUOTES, 'UTF-8' ) ) );
echo "Video:<br />{$html['video']}<hr />";
} ?>

UPDATE: This is what the embed code looks like in the DB:

<object width=\"450\" height=\"380\"><param name=\"movie\" value=\"http://www.youtube.com/v/Z5j3CORfxmw&hl=en_US&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/Z5j3CORfxmw&hl=en_US&fs=1&rel=0&color1=0x3a3a3a&color2=0x999999\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"450\" height=\"380\"></embed></object>

The php code right above it pulls out this data, without the slashes and it displays the embed code perfectly as text, but the actual video does not form from that. Is there anyway to have the code displayed act as code and show the video instead of text?


Why would you want to do this, why not simply save the various parameters values and recreate the embed code in your PHP script?

This would be more flexible & future proof. Let's imagine, for example , that the embed code format is changed next year, you'd have to entirely modify your database records as opposed to updating a single script.

//Assuming that you have saved a JSON string in Mysql
$video = json_decode($video_data);

<object width="<? = $video->width;>" height="<? = $video->height;>">
   <param name="movie"    
          value="<? = $video->url;>"></param>
   <param name="allowFullScreen" 
   <param name="allowscriptaccess" 
   <embed src="<? = $video->url;>" 
          width="<? = $video->width;>" height="<? = $video->height;>"></embed>