Can't get song to play when pulling from database

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
phillyrob
Forum Commoner
Posts: 34
Joined: Wed Jun 18, 2008 12:00 am

Can't get song to play when pulling from database

Post 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?
crmalibu
Forum Newbie
Posts: 5
Joined: Sat Jul 05, 2008 12:53 am

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

Post 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. :)
phillyrob
Forum Commoner
Posts: 34
Joined: Wed Jun 18, 2008 12:00 am

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

Post 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.
crmalibu
Forum Newbie
Posts: 5
Joined: Sat Jul 05, 2008 12:53 am

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

Post 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.
Post Reply