Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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.

share|improve this question
1  
Add error reporting to the top of your file(s) right after your opening <?php tag error_reporting(E_ALL); ini_set('display_errors', 1); see if it yields anything, including or die(mysql_error()) to mysql_query(). – Fred -ii- Sep 7 '14 at 15:16
    
nope,not getting any error report. – YoJackal Sep 7 '14 at 15:28
    
is albumid is not integer you need to enclose it in quotes – undefined_variable Sep 7 '14 at 15:36
    
You mean like this? : ("SELECT * FROM songs WHERE 'album_id = $album_id'") Doesn't seems to make any difference. – YoJackal Sep 7 '14 at 15:47

try this code :

while ($fetch_songs = mysql_fetch_array($query, MYSQL_ASSOC))

more information : http://php.net/manual/en/function.mysql-fetch-array.php

share|improve this answer
    
Still getting an empty album :( – YoJackal Sep 7 '14 at 15:30
    
echo $song_name and $song_path in while and copy the result here. – PKa Sep 7 '14 at 15:52
    
Mmm,that's weird. still nothing. so the problem is with the SQL query? cause its doesn't seems to read the data from the DB. – YoJackal Sep 7 '14 at 16:07
    
use "SELECT * FROM songs WHERE album_id = 1" ,at MYSQL(SQL tab) to check your query. – PKa Sep 7 '14 at 16:15
    
But 'album_id' is a varchar(yeah,I know,that's kinda stupid) its the name of the album. that's why there is the $album_id variable. even if I'm trying : ("SELECT 'name','path' FROM songs WHERE 'album_id = Superunknown'") To get that specific album I'm still getting nothing. – YoJackal Sep 7 '14 at 16:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.