Jump to content

Embedding Youtube video via php?


immunity

Recommended Posts

How i can do it ? if i echo  the embed whole (with address to ) its work fine (althought i dont want it!)

 

but if i put the url in a variable  it doesnt work  like this :

 

<?php 
$s = "http://www.youtube.com/watch?v=_i2MSvaZeqw";

echo "<object type=\"application/x-shockwave-flash\" style=\"width:425px; height:350px;\" data=\"".$s."\"><param name=\"movie\" value=\"".$s."\" /></object>" ;
?>

Link to comment
https://forums.phpfreaks.com/topic/52976-embedding-youtube-video-via-php/
Share on other sites

it's created a parsing error

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/other/db2student/labdb219/public_html/asdf.php on line 20

 

line 20 is the  echo"code for embedding youtube";

 

do i have to do something on $s?

<?php 
$con = mysql_connect("localhost","labdb2_19","2004040");
			if (!$con)
		    {
	  			die('Could not connect: ' . mysql_error());
	  		}
			mysql_select_db("labdb2_19", $con);
	  		$sql = "SELECT youtube FROM movie WHERE title ='Spider-man3'";
	  		$result = mysql_query($sql);
			while ($row = mysql_fetch_assoc($result)) 
			{
				echo "<object width=\"425\" height=\"350\"><param name=\"movie\" value=\"$row['youtube']\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"$row['youtube']\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"425\" height=\"350\"></embed></object> ";

			}

			mysql_free_result($result);
			mysql_close($con);

?>

 

its the whole code in the page (nothing else)

 

result from putty http://195.251.111.53/~labdb219/putty.JPG

<?php 
$con = mysql_connect("localhost","labdb2_19","2004040");
			if (!$con)
		    {
	  			die('Could not connect: ' . mysql_error());
	  		}
			mysql_select_db("labdb2_19", $con) or die(mysql_error());
	  		$sql = "SELECT youtube FROM movie WHERE title ='Spider-man3'";
	  		$result = mysql_query($sql) or die(mysql_error());
			while ($row = mysql_fetch_assoc($result)) 
			{
				echo "<object width=\"425\" height=\"350\"><param name=\"movie\" value=\"$row['youtube']\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"$row['youtube']\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"425\" height=\"350\"></embed></object>";

			}

			mysql_free_result($result);
			mysql_close($con);

?>

 

Added a bit of debugging.

Silly me. Didn't spot that you missed out your final } brace!

 

<?php 
$con = mysql_connect("localhost","labdb2_19","2004040");
			if (!$con)
		    {
	  			die('Could not connect: ' . mysql_error());
	  		}
			mysql_select_db("labdb2_19", $con) or die(mysql_error());
	  		$sql = "SELECT youtube FROM movie WHERE title ='Spider-man3'";
	  		$result = mysql_query($sql) or die(mysql_error());
			while ($row = mysql_fetch_assoc($result)) 
			{
				echo "<object width=\"425\" height=\"350\"><param name=\"movie\" value=\"$row['youtube']\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"$row['youtube']\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"425\" height=\"350\"></embed></object>";

			}

			mysql_free_result($result);
			mysql_close($con);

		    }

?>

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.