Forum Moderators: coopster

Message Too Old, No Replies

Php Form Question

Users select video clips from a form and the video is displayed dynamically

         

bulungu

8:41 pm on Apr 22, 2005 (gmt 0)

10+ Year Member



Hi Everyone:
It's my fault. I should have learned Php a long time ago. Now I need your help.

I have an HTML form that uses JavaScript to go to different video clips that I have already embeded in specific web pages (i.e. video1.html, video2.html, video3.html, etc.) Now, I think that if my form uses the "POST" method I should be able to dynamically have a page called "video.php" to play all videos instead of having to manually create these page.

These videos are files like "video1.wmv" or playlists such as "video.m3u".

Can you please help me with the "video.php" and what else do I need on the following form?

<html><head><title>Video Selection</title>
<script language="JavaScript">
<!--
//

function openDir(form) {
window.location=(form.dir.options[form.dir.selectedIndex].value);
}
// -->
</script>
</head>

<body>
<form name="Video_On_Demand">
<div align="center"><p align="left"><select name="dir" size="1">
<option>Select a Video</option>
<option value="video1.html>Week 1
<option value="video2.html">Week 2
<option value="video3.html">Week 3
<option value="video4.html">Week 4
</select><input type="button" name="button" value="Go!" onclick="openDir(this.form);"> </p>
</div>
</form>
</body>
</html>

StupidScript

10:56 pm on Apr 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Howdy!

<option value="video1.html>Week 1 

<option value="video2.html">Week 2 

<option value="video3.html">Week 3 

<option value="video4.html">Week 4 

could easily be changed to:

<option value="video.php?vid=video1&type=wmv>Week 1 

<option value="video.php?vid=video2&type=mov">Week 2 

<option value="video.php?vid=video3&type=wmv">Week 3 

<option value="video.php?vid=video1$type=m3u">Week 4 

and video.php could be something like:

<?php
$thisVideo = $_POST['vid'].".".$_POST['type'];

switch $_POST['type'] {

case "wmv":
$thisClass="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95";
$thisType="application/x-oleobject";
$thisCodebase="http://activex.microsoft.com/..et..al..";
$thisEmbedType="application/x-mplayer2";
$thisCustom="<param name='autostart' value='true'><param name='autorewind' value='true'>";
$thisEmbedCustom="autostart=true showpositioncomtrols=1";
break;

case "mov":
$thisClass="clsid:for_quicktime_movies";
$thisType="video/quicktime";
$thisCodebase="http://quicktime_code_base_uri/..et..al..";
$thisEmbedType="video/quicktime";
$thisCustom="";
$thisEmbedCustom="";
break;

[dupe above for other media types]

}
echo "<object id='thamovie' classid='".$thisClass."' type='".$thisType."' codebase='".$thisCodebase;
echo "' width=320 height=240>\n";
echo "<param name='filename' value='".$thisVideo."'>\n";
echo $thisCustom;
echo "<embed type='".$thisEmbedType."' name='thamovie' src='".$thisVideo;
echo " width=320 height=240 ".$thisEmbedCustom."></embed>\n";
echo "</object>\n";
?>

You could include other things, too like alternate widths and heights, etc.

See the PHP manual [php.net] for more info about the "switch" statement.

<edit>broke lines unnaturally to avoid confusing wrap</edit>

bulungu

12:36 am on Apr 23, 2005 (gmt 0)

10+ Year Member



Thank you very much StupidScript. Your posting really is helpful. I have not tested it on a commercial web server yet. I just tried it on a school server and here is the error I received:

PHP Parse error: parse error, expecting `'('' in D:\Inetpub\wwwroot\bulungu\videos\video.php on line 4

Of course, bulungu is the login/account name. It seems like something is expected on line 4 of video.php.

Any idea?

Regards

bulungu

1:03 am on Apr 23, 2005 (gmt 0)

10+ Year Member



Hi StupidScript:

I've tested it on a commercial web server that supports PhP and I got pretty much the same error:

Parse error: parse error, expecting `'('' in /data/web/75050/www/php/video.php on line 4

Apparently something is expected on line 4 of video.php.

jd01

1:40 am on Apr 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi bulungu,

Not something I use too often, but I believe you need to parenthesize(SP?) () switch.

EG switch ($_POST['type']) {

Looks like this is the problem, sometimes php doesn't 'break' on the exact line of the error...

Hope this helps.

Justin

bulungu

11:53 am on Apr 23, 2005 (gmt 0)

10+ Year Member



Greetings JDO1:

I tried switch ($_POST['type']) { on what I thought was line 4 but I still got the same parse error. I went back and deleted the break so that the "switch" statement starts on line 3 to see if that's where the error was coming from. I received the same message saying that the parse error was on line 4.

I now think that it has something to do with the first "case" statement since PHP executes statement by statement instead of line by line. I checked the PHP manual, and to me it seems like the string is properly double-quoted ("") and does have the colon (:) at the end. Single-quoting the string 'wmv' did not help either.

Any idea?

Thanks in advance.

bulungu

bulungu

3:13 pm on Apr 23, 2005 (gmt 0)

10+ Year Member



Yes, I found the problem. It's on the 4th statement:

case "wmv": should be case "wmv"; (; vs :)

But php won't play the videos for some reasons. Here is the new fatal error:

PHP Fatal error: Unable to open D:\Inetpub\wwwroot\bulungu\videos\video.php in Unknown on line 0

Oh boy, I've never heard of line 0 before. Maybe someone has. Help will be appreciated.

jd01

5:10 pm on Apr 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi bulungu,

Actually, my idea was that you should add () to the switch statement you already have on the line that it is already on... Line 2.

<?php
$thisVideo = $_POST['vid'].".".$_POST['type'];

switch ($_POST['type']) {

Sometimes, when php encounters an error, it keeps reading past where the error is, becuase it tries to find what it is looking for, and then finally can't. So, it is possible to have an error on lines that are directly above where the error is recorded, but no error on the actual line that is in the 'error' message.

Also, I believe the "proper" and "safe" way to use the variable $_POST['type'] is to 'catch' the variable prior to using it is. EG:

$thisVideo = $_POST['vid'].".".$_POST['type'];

new line 2: $type = $_POST['type']; (added)
new line 3: switch ($type) {

This way the actual 'POST' variable could be tested for 'bad-stuff' before use. (testing not shown in the example) I don't think it's overly necessary here, but still a good habit.

Sorry, if this or the original post is confusing.

Hope it helps.

Justin

PS like I said before, switch/case are not something I use much, so not to technical with them... I'll leave it to the pro's now.

bulungu

12:35 pm on Apr 24, 2005 (gmt 0)

10+ Year Member



Thanks JD01:

I will try to implement it and see what comes up. I will start a new thread if I cannot get it to work.

Regards,

Bulungu.

StupidScript

6:12 pm on Apr 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry bulungu and thanks jd01.

1: <?php 

2: $thisVideo = $_POST['vid'].".".$_POST['type']; 

3:

4: switch $_POST['type'] { 

Indeed, I mis-wrote originally. Should be:

switch ($_POST['type']) {

Otherwise it goes as above:

case [i]condition1[/i]:

[i]action to take[/i];

[i]more actions ...[/i];

break;

case [i]condition2[/i]:

[i]action to take[/i];

break;

etc.

Check out the PHP manual page I linked to in my first message for "switch()" function info.

bulungu

7:33 pm on Apr 26, 2005 (gmt 0)

10+ Year Member



Thanks StupidScript:

I added the () and the parse error is gone. The PhP page loads when I select a video and click "GO." However, the page is blank. It looks like it doesn't see the videos.

For testing purpose I have the videos and the html and the php files in the same folder. The address bar shows the URL like:

[example.com...] but the page is blank. The video "car1.wmv" can play when embedded in HTML but not in PHP. Do I need to specify a placeholder or something?

StupidScript

11:00 pm on Apr 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You would use the PHP to write the HTML. As far as the server is concerned, as long as it can understand what is being asked of it, it will deliver whatever you want. As long as the browser is requesting it properly, there should be no problem.

Please paste the resulting HTML (not the PHP, the view->source in the browser) that makes up the blank page you get, and we'll take a look. The solution will be related to how the HTML was written.

bulungu

11:58 pm on May 1, 2005 (gmt 0)

10+ Year Member



Sorry StupidScript. I was caught up in other things and now I'm ready again. Here are the results of the PHP page:

<object id='thamovie' classid='' type='' codebase='' width=320 height=240>
<param name='filename' value='.'>
<embed type='' name='thamovie' src='. width=320 height=240 ></embed>
</object>