I have created a blog where the user has the ability to upload a file. If the user uploads an mp3 file, an image displays telling the user to click it in order to play the track. When the image is clicked, it displays a Flash mp3 player. I have got that far. Then I want the MP3 player to display the track that the user has uploaded with that particular blog post. Note - the name of the track is inserted into the database under the fieldname 'file' when the user uploads it.
I have been able to get the mp3 player to show all of the files under the fieldname 'file', but I only want the file associated with that particular blog post to show.
This is the code within my blog post loop;
if (strstr($image,'mp3')) {
echo "<form action='blogmusic.php' method='post'>";
echo "<input type='hidden' name='idb' value='$id' />";
echo "<img id='mp3image' class='blogimage' onclick='gotoplayer();' src='images/mp3image.png' alt='' />";
echo "</form>";
echo "<object id='blogplayer' class='blogimage' style='display:none' type='application/x-shockwave-flash' data='blogplayer.swf' width='177' height='119'> <param name='movie' value='blogplayer.swf' /> <param name='wmode' value='transparent' /> </object>";
Then this is the code in blogmusic.php;
<?php
require_once('config.php');
$mysql = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
mysql_select_db(DB_DATABASE);
$idb = $_POST['idb'];
$Query="SELECT file FROM news WHERE id = $idb";
$Result=mysql_query( $Query );
$Return="<?xml version=".'"1.0"'." encoding=".'"UTF-8"?>'."\n"."<music>";
while($music=mysql_fetch_assoc($Result))
{
$song = $music['file'];
$Return.="<song id='blogfiles/$song' disp='$song' />";
}
$Return.="</music>";
mysql_free_result($Result);
echo ($Return);
?>
To my logic, this should make the mp3 player display the file associated with each particular blog post. But it does not display anything. If I remove the 'WHERE id=$idb' from the sql query, the mp3 player shows all of the records under 'file' in the database.
Any help on this? Many thanks.