Page 1 of 1

Can't get song to play when pulling from database

Posted: Sat Jul 05, 2008 7:34 pm
by phillyrob
I have an interesting issue. When I manually type a url-encoded song title and echo it, it will play in my flash song player using AS2, but when I pull the song title from the database and echo it in the same format it won't play. The name of the song is "As" by Stevie Wonder. When I manually type it in like this: echo "&title=As&"; It echos to the screen in just that format, and I can pick it up as a variable in Actionscript 2 and play it. But when I do it like this:

$string2 = $_POST['Song'];

$rs2 = mysql_query("SELECT * FROM mymusic where song = '$string2'");
$row2 = mysql_fetch_array($rs2);
$sng = $row2['Song'];

echo "&title=$sng&"

it echos to the screen fine, and in the exact format as the manual echo, but it won't play. does anyone have any ideas as to why?

Re: Can't get song to play when pulling from database

Posted: Sat Jul 05, 2008 11:24 pm
by crmalibu
Try

Code: Select all

var_dump($row2['Song']);
to make sure theres no hidden characters you can't see.

Also, where does the file get loaded from? Is it a direct url to an actual file, or does the url point to another script, which serves the file? Is it possible theres something hanging this script up momentarily? If sessions are involved, race conditions can exist which can cause seemingly strange behavior(although its logical why this happens). Im thinking you use php sessions to authenticate the user so your script which serves the media can deny people without a valid session, in which case you need to tweak it. :)

Re: Can't get song to play when pulling from database

Posted: Sun Jul 06, 2008 12:40 am
by phillyrob
Thanks, I ran the var_dump($row2['Song']); and it came up null. This$row2['Song'])'s output is picked up by Actionscript and turned into a variable that calls the mp3 file directly. There are no sessions running. Thanks for your input btw. I am at a loss because again it echoes to the screen from the database identical to the manual echo.

Re: Can't get song to play when pulling from database

Posted: Sun Jul 06, 2008 11:11 am
by crmalibu
var_dump() would not output null if the same variable is outputting a value when echo'd.
You must be calling var_dump() from a different location in the script where that variable is out of scope.