I am kinda new to PHP and I am buliding a music library as a school project.
There is a Table 'albums' which holds 'id' and 'name'. and a table 'songs' containing 'id','name','album_id' and 'path'.
Long story short,I am trying to display all the songs that are in the selected album. user creates an album and then uploads songs into it.that part works great and the DB is filled in correctly. problem is, once I select an album to view the songs that are in it I get nothing.
<?php
$album_id = $_GET['id'];
//display songs from selected album
$query = mysql_query("SELECT * FROM songs WHERE album_id = $album_id");
while ($fetch_songs = mysql_fetch_array($query)) {
$song_name = $fetch_songs['name'];
$song_path = $fetch_songs['path'];
?>
<a href="music/<?php echo $song_path ?>">play song</a>
<br/>
<b><?php echo $song_name; ?></b>
<?php
}
?>
</div>
I believe using a href would be the simplest option, yet I've tried also audio controls and even trying to upload an image with img src istead of an MP3 and still no success, I just get an empty page.
this is the code for song uploading to DB.
if (isset($_POST["upload"])) {
$name = $_POST['name'];
$album_id = $_POST['album'];
$file_name = $_FILES['file']['name'];
$file_type = $_FILES['file']['type'];
$file_size = $_FILES['file']['size'];
$file_tmp = $_FILES['file']['tmp_name'];
$random_name = rand();
if (empty($name) || empty($file_name)) {
echo "Please fill all fields in the form ! <br/>";
} else {
move_uploaded_file($file_tmp, 'music/' . $random_name . '.mp3');
mysql_query("INSERT INTO songs VALUES ('','$name','$album_id','$random_name.mp3')");
echo "File uploaded ! </br></br>";
}
}
?>
Thanks for any help.
<?php
tagerror_reporting(E_ALL); ini_set('display_errors', 1);
see if it yields anything, includingor die(mysql_error())
tomysql_query()
. – Fred -ii- Sep 7 '14 at 15:16