This old scripts worked, but not combined into one

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

This old scripts worked, but not combined into one

Post by toasty2 »

Ok, I had my nice little radio script using frames, and 3 different scripts. Now, for simplicity, I decided to make them into one page. But, after doing this, they do not work. Here's the list songs script combined with the play song script. It shows the song list, but does not show the play song part at all.

Code: Select all

<html><head>
</head>
<body  alink="green" vlink="green" link="green">
<font face="arial">
&nbsp;<font color=green><big>Radio</big></font><small><font color=lightblue><i>Beta</i></font></small>
<small></small>
<br>

<select name="song" onChange="document.location.href=document.nav.SelectURL.options[document.nav.SelectURL.selectedIndex].value">
<option value="#" selected>&nbsp;&nbsp;Select Song</option>
<!-- MP3s -->
<?php
//define the path as relative
$path = "/homepages/21/d155481990/htdocs/server/songs";
//using the opendir function
$dir_handle = @opendir($path) or die("Error, oh noez!");
// While loop
while ($file = readdir($dir_handle)) 
{
   if($file!="." && $file!=".." && $file!="index.php" && $file!="about.html")
	{
	$newfile = str_replace(".mp3", "", $file);
	$newerfile = str_replace("_", " ", $newfile);
	$newerfile = ucwords($newerfile);
      echo "<option value=\"?song=$newfile\" target=\"song\">$newerfile</option>";
	}
}
//closing the directory
closedir($dir_handle);

// SONG 

		// Play Song Code
$song = $_GET['song'];
if ($song == null)
{
echo "No song selected.<br>";
}
else
{
echo "Filename: \"$song.mp3\"<br><embed SRC=\"http://randomresources.com/server/songs/$song.mp3\" AUTOSTART=\"true\"  HIDDEN=\"true\" LOOP=\"0\" VOLUME=\"100\">";
}
//Reads ID3v1 from a MP3 file and displays it
    $mp3 = "songs/$song.mp3"; //MP3 file to be read
    $filesize = filesize($mp3);
    $file = fopen($mp3, "r");
    fseek($file, -128, SEEK_END);
    $tag = fread($file, 3);    
    if($tag == "TAG")
    {
        $data["Song"] = trim(fread($file, 30));
        $data["Artist"] = trim(fread($file, 30));
        $data["Album"] = trim(fread($file, 30));       
    }
	else
	{
		die("MP3 information could not be read.");
	}
    fclose($file);
    while(list($key, $value) = each($data))
    {
        print("$key: $value<br>\r\n");    
    }
?></small></font>

</font>
</body>
</html>
Last edited by toasty2 on Sat Sep 30, 2006 11:03 pm, edited 5 times in total.
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

Whoa, I messed up somewhere, it isn't being highlighted correctly, someone want to help me with that?
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post by wtf »

First thing I can see it <a href="$__SELF__">Stop</a>

try changing that to <a href=<?php echo $__SELF__; ?> then see what happens.
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

That's in a comment..."<!-- -->", how would that affect it?

Now the code shows and highlights correctly. The problem was "<!-- MP3's -->", the single-quote that was meant to be an apostraphe tricked the highlighter. Apparently the highlighter doesn't know how to read HTML comments. Anyway, that was not the problem with my code, it still doesnt work.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

You're not closing the <select> tag...
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

Ok, but that does not have anything to do with it not displaying the play song section.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

not? It makes the embed element a child of the select element. That's most probably invalid.
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

That's not my concern right now, the play song output isnt even in the source! That means for some reason php isn't outputing the play song part. It only ouputs this:

Code: Select all

<html><head>
</head>
<body  alink="green" vlink="green" link="green">
<font face="arial">
&nbsp;<font color=green><big>Radio</big></font><small><font color=lightblue><i>Beta</i></font></small>
<small></small>
<br>

<select name="song" onChange="document.location.href=document.nav.SelectURL.options[document.nav.SelectURL.selectedIndex].value">
<option value="#" selected>&nbsp;&nbsp;Select Song</option>

<option value="?song=song1" target="song">Song1</option>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

so
// Play Song Code
$song = $_GET['song'];
if ($song == null)
{
echo "No song selected.<br>";
}
else
{
echo "Filename: \"$song.mp3\"<br><embed SRC=\"http://randomresources.com/server/songs/$song.mp3\" AUTOSTART=\"true\" HIDDEN=\"true\" LOOP=\"0\" VOLUME=\"100\">";
}
it's displaying No song selected.?
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

No, its displaying nothing. :cry:
So, that means that php is stopping for some reason before that code or something.
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post by wtf »

GWsux wrote:That's in a comment..."<!-- -->", how would that affect it?
That is a client side comment. If that variable is not getting the value on the server it could affect who knows what.
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

That has nothing to do with the script not outputing the play song html, it has no relevance to the current problem. As you can see, the play song code that should be outputted is not, here's the demo: http://toastradio.randomresources.com/compact.php
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

What's the very last thing that is shown in the browser's source view?
Is your script running with error_reporting=E_ALL and maybe with display_errors=true?
Have you checked the script for syntax errors?

edit: it says
http://toastradio.randomresources.com/compact.php wrote:21st Century Schizoid Man</option>No song selected.<br>MP3 information could not be read.
and you would have seen this if the select element had been closed.
toasty2
Forum Contributor
Posts: 361
Joined: Wed Aug 03, 2005 10:28 am
Location: Arkansas, USA

Post by toasty2 »

Ok its fixed. I dont want to make a new topic, but I have a question on Javascript. I'll just ask it anyway. When one of the options in the select is chosen, it should change to the url that the value has. But, it isn't. Does anyone know how to fix that?

Code: Select all

<select name="song" onChange="document.location.href=document.nav.SelectURL.options[document.nav.SelectURL.selectedIndex].value">
<option value="#" selected>&nbsp;&nbsp;Select Song</option>
<option value="?song=would" selected>Would</option>
</select>
Why is it not changing the page? Can anyone correct it?
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post by wtf »

nav element on your page does not exist and your js is crashing

following should fix your problem

<select id="song" name="song" onChange="document.location.href=document.getElementById( 'song' ).options[document.getElementById( 'song'

)
.selectedIndex].value">
Post Reply