Page 1 of 1

This old scripts worked, but not combined into one

Posted: Sat Sep 30, 2006 10:48 pm
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>

Posted: Sat Sep 30, 2006 10:51 pm
by toasty2
Whoa, I messed up somewhere, it isn't being highlighted correctly, someone want to help me with that?

Posted: Sat Sep 30, 2006 10:59 pm
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.

Posted: Sat Sep 30, 2006 11:00 pm
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.

Posted: Sun Oct 01, 2006 12:29 am
by nickvd
You're not closing the <select> tag...

Posted: Sun Oct 01, 2006 2:31 pm
by toasty2
Ok, but that does not have anything to do with it not displaying the play song section.

Posted: Sun Oct 01, 2006 2:45 pm
by volka
not? It makes the embed element a child of the select element. That's most probably invalid.

Posted: Sun Oct 01, 2006 3:45 pm
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>

Posted: Sun Oct 01, 2006 3:53 pm
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.?

Posted: Sun Oct 01, 2006 4:10 pm
by toasty2
No, its displaying nothing. :cry:
So, that means that php is stopping for some reason before that code or something.

Posted: Sun Oct 01, 2006 4:20 pm
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.

Posted: Sun Oct 01, 2006 4:24 pm
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

Posted: Sun Oct 01, 2006 4:31 pm
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.

Posted: Sun Oct 01, 2006 7:32 pm
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?

Posted: Sun Oct 01, 2006 10:34 pm
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">