Jump to content

Trying to swap videos on a webpage but my variables are showing up blank


djkirstyjay

Recommended Posts

Hi there!

 

I'm having a bit of a problem that I can't seem to see why it's not working.

 

I'm a teacher, and I've been doing a project with the kids where I have taken videos of them telling the weather forecast.

 

I have processed them and uploaded them to youtube, and I have created a really simple webpage with a TV screen on it and a remote.

 

I want the videos to appear in the TV screen, and when the buttons are pressed on the remote, the videos will change to show the relevant classes video.

 

I am using code that I have written in the past and it works for swapping stuff, so I'm unsure why it is not happening for me this time. Could someone take a quick look and tell me if you can see what it is that's going wrong...

 

When I look at the source code, it's not showing my '$vid' variable, which should contain the youtube video code, but I don't know why it's not showing up.

 

See the page in action HERE. (I have not resized the TV image to the video yet, as I need to get it working first!)

 

Here's the source code :

<?
setcookie("movie",$movie);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>What's The Weather Like?</title>

<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper">
  
  <div id="remote"><img src="remote-sm.jpg" width="221" height="700" border="0" usemap="#Video1" />
    <map name="Video1" id="Video1">
      <area shape="circle" coords="109,500,14" href="#" alt="6º" />
      <area shape="circle" coords="68,502,15" href="<?php echo $_SERVER['PHP_SELF']; ?>?vid=IzJP6H0QgHI" alt="5º" />
      <area shape="circle" coords="151,465,14" href="#" alt="4º" />
      <area shape="circle" coords="109,465,14" href="<?php echo $_SERVER['PHP_SELF']; ?>?vid=oT33ewdRJbA" alt="3º" />
      <area shape="circle" coords="68,466,14" href="<?php echo $_SERVER['PHP_SELF']; ?>?vid=yJ_QAP7w8oo" alt="2º" />
      <area shape="circle" coords="110,238,19" href="#" alt="English Blog" />
      <area shape="rect" coords="97,36,123,59" href="#" alt="Homepage" />
    </map>
  </div><!-- END remote -->

  <div id="header">
  <h3>What's the weather like today?</h3>
  </div><!-- END header -->
  
  <div id="tv">
  
  	<div id="video">
  
  <?php 
  
  $url = "<object width=\"640\" height=\"385\"><param name=\"movie\" value=\"http://www.youtube.com/v/" . $vid . "?fs=1&hl=en_GB\"></param><param name=\"allowFullScreen\" value=\"false\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/" . $vid . "?fs=1&hl=en_GB\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"false\" width=\"640\" height=\"385\"></embed></object>";
  
if(isset($vid)) {
    echo $url;
   } 
else {
$vid = "IzJP6H0QgHI";
        echo $url;
}
?>
    
    </div><!-- END video -->
    
  </div><!-- END tv -->
  
</div><!-- END wrapper -->
</body>
</html>

 

I made a few changes for starters you had <?php to start your php everywhere except for where you set the cookie. Also after checking your source code you have 2 question marks so I changed the later one to an ampersand that is how the get method is formed in headers. Please tell me if this works for you.

 

<?php
setcookie("movie",$movie);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>What's The Weather Like?</title>

<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper">

  <div id="remote"><img src="remote-sm.jpg" width="221" height="700" border="0" usemap="#Video1" />
    <map name="Video1" id="Video1">
      <area shape="circle" coords="109,500,14" href="#" alt="6º" />
      <area shape="circle" coords="68,502,15" href="<?php echo $_SERVER['PHP_SELF']; ?>?vid=IzJP6H0QgHI" alt="5º" />
      <area shape="circle" coords="151,465,14" href="#" alt="4º" />
      <area shape="circle" coords="109,465,14" href="<?php echo $_SERVER['PHP_SELF']; ?>?vid=oT33ewdRJbA" alt="3º" />
      <area shape="circle" coords="68,466,14" href="<?php echo $_SERVER['PHP_SELF']; ?>?vid=yJ_QAP7w8oo" alt="2º" />
      <area shape="circle" coords="110,238,19" href="#" alt="English Blog" />
      <area shape="rect" coords="97,36,123,59" href="#" alt="Homepage" />
    </map>
  </div><!-- END remote -->

  <div id="header">
  <h3>What's the weather like today?</h3>
  </div><!-- END header -->

  <div id="tv">

     <div id="video">

  <?php 
  
  $url = "<object width=\"640\" height=\"385\"><param name=\"movie\" value=\"http://www.youtube.com/v/" . $vid . "&fs=1&hl=en_GB\"></param><param name=\"allowFullScreen\" value=\"false\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/" . $vid . "&fs=1&hl=en_GB\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"false\" width=\"640\" height=\"385\"></embed></object>";
  
if(isset($vid)) {
    echo $url;
   } 
else {
   $vid = "IzJP6H0QgHI";
        echo $url;
   }
   ?>
   
    </div><!-- END video -->
   
  </div><!-- END tv -->

</div><!-- END wrapper -->
</body>
</html>

 

Also may I ask the age group of the students you are having do this? I am 17 and I was just kind of curious.

Thanks,

Colton Wagner

Actually void the last code and replace it with this. You never set your $vid variable.

 

<?php
setcookie("movie",$movie);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>What's The Weather Like?</title>

<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper">

  <div id="remote"><img src="remote-sm.jpg" width="221" height="700" border="0" usemap="#Video1" />
    <map name="Video1" id="Video1">
      <area shape="circle" coords="109,500,14" href="#" alt="6º" />
      <area shape="circle" coords="68,502,15" href="<?php echo $_SERVER['PHP_SELF']; ?>?vid=IzJP6H0QgHI" alt="5º" />
      <area shape="circle" coords="151,465,14" href="#" alt="4º" />
      <area shape="circle" coords="109,465,14" href="<?php echo $_SERVER['PHP_SELF']; ?>?vid=oT33ewdRJbA" alt="3º" />
      <area shape="circle" coords="68,466,14" href="<?php echo $_SERVER['PHP_SELF']; ?>?vid=yJ_QAP7w8oo" alt="2º" />
      <area shape="circle" coords="110,238,19" href="#" alt="English Blog" />
      <area shape="rect" coords="97,36,123,59" href="#" alt="Homepage" />
    </map>
  </div><!-- END remote -->

  <div id="header">
  <h3>What's the weather like today?</h3>
  </div><!-- END header -->

  <div id="tv">

     <div id="video">

  <?php 
  
if(isset($_GET['vid'])) {
$vid = $_GET['vid'];
    echo "<object width=\"640\" height=\"385\"><param name=\"movie\" value=\"http://www.youtube.com/v/" .$vid. "?fs=1&hl=en_GB\"></param><param name=\"allowFullScreen\" value=\"false\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/" .$vid. "?fs=1&hl=en_GB\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"false\" width=\"640\" height=\"385\"></embed></object>";;
   } else {
$vid = "IzJP6H0QgHI";
        echo "<object width=\"640\" height=\"385\"><param name=\"movie\" value=\"http://www.youtube.com/v/" .$vid. "?fs=1&hl=en_GB\"></param><param name=\"allowFullScreen\" value=\"false\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/" .$vid. "?fs=1&hl=en_GB\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"false\" width=\"640\" height=\"385\"></embed></object>";;
   }
   ?>
   
    </div><!-- END video -->
   
  </div><!-- END tv -->

</div><!-- END wrapper -->
</body>
</html>

 

Sorry for the invaluable post.

Thanks,

Colton Wagner

I made a few changes for starters you had <?php to start your php everywhere except for where you set the cookie. Also after checking your source code you have 2 question marks so I changed the later one to an ampersand that is how the get method is formed in headers. Please tell me if this works for you.

 

Thanks! Will give it a go now, as I was hoping to show it to them today in class! :D

Also may I ask the age group of the students you are having do this? I am 17 and I was just kind of curious.

Thanks,

Colton Wagner

The kids are between 7 & 11 years old. I teach English as a second language. Next project is a live TV show on Justin TV :D

Well... thanks for cleaning up the code, as it didn't spot the things you mentioned, but it's still not working!

 

I tried both with and without the '?'s, as this is part of the youtube embed code that was given, which I just escaped out all the quotes with slashes.

 

For some reason, it will not but the youtube code in the variable $vid in the url.... WHY oh WHY oh WHY????? Argh!

 

Please help! :D

 

 

 

I have the code working here:http://kno3technology.com/apps/video-fix.php

 

code:

 

<?php
setcookie("movie",$movie);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>What's The Weather Like?</title>

<link href="http://www.kirstyjay.com/television/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper">

  <div id="remote"><img src="http://www.kirstyjay.com/remote-sm.jpg" width="221" height="700" border="0" usemap="#Video1" />
    <map name="Video1" id="Video1">
      <area shape="circle" coords="109,500,14" href="#" alt="6º" />
      <area shape="circle" coords="68,502,15" href="<?php echo $_SERVER['PHP_SELF']; ?>?vid=IzJP6H0QgHI" alt="5º" />
      <area shape="circle" coords="151,465,14" href="#" alt="4º" />
      <area shape="circle" coords="109,465,14" href="<?php echo $_SERVER['PHP_SELF']; ?>?vid=oT33ewdRJbA" alt="3º" />
      <area shape="circle" coords="68,466,14" href="<?php echo $_SERVER['PHP_SELF']; ?>?vid=yJ_QAP7w8oo" alt="2º" />
      <area shape="circle" coords="110,238,19" href="#" alt="English Blog" />
      <area shape="rect" coords="97,36,123,59" href="#" alt="Homepage" />
    </map>
  </div><!-- END remote -->

  <div id="header">
  <h3>What's the weather like today?</h3>
  </div><!-- END header -->

  <div id="tv">

     <div id="video">

  <?php 
  
if(isset($_GET['vid'])) {
$vid = $_GET['vid'];
    echo "<object width=\"640\" height=\"385\"><param name=\"movie\" value=\"http://www.youtube.com/v/" .$vid. "?fs=1&hl=en_GB\"></param><param name=\"allowFullScreen\" value=\"false\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/" .$vid. "?fs=1&hl=en_GB\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"false\" width=\"640\" height=\"385\"></embed></object>";;
   } else {
   $vid = "IzJP6H0QgHI";
        echo "<object width=\"640\" height=\"385\"><param name=\"movie\" value=\"http://www.youtube.com/v/" .$vid. "?fs=1&hl=en_GB\"></param><param name=\"allowFullScreen\" value=\"false\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/" .$vid. "?fs=1&hl=en_GB\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"false\" width=\"640\" height=\"385\"></embed></object>";;
   }
   ?>
   
    </div><!-- END video -->
   
  </div><!-- END tv -->

</div><!-- END wrapper -->
</body>
</html>

That's fantastic! I have it working now, however in the first two lines of code, it must say :

 

<?php

setcookie("vid",$vid);

?>

 

as the variable name is vid, not movie... my original mistake, but seems to have followed through :)

 

Thanks! I have bigger plans that I can now introduce. :D

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.