Master-Detail coding problem

Codes here !

Moderators: egami, macek, gesf

Post Reply
nfhopmike
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Nov 12, 2018 9:33 am

Mon Nov 12, 2018 9:56 am

I have an audio playlist that is set up as a master-detail set, where the master page is produced as an html table with one of the columns clickable. This sends the id to the detail page in the form "audioplayer.php?id=3" or whatever the id of that track is. This part is working successfully and is passing the id OK.
Where I am having problems is getting the detail page - audioplayer.php - to work. What should happen is when the link is selected, the audioplayer page should open displaying an html5 audio player to play the mp3 file, which is downloaded from Amazon S3 repository. However I cannot seem to get the detail page working. At present I am getting two errors:

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\wamp64\www\miketest\audioplayer.php on line 19

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\wamp64\www\miketest\audioplayer.php on line 21

I would be grateful if anyone can help me correct these errors and get the code working.

Master page:

Code: Select all

 <?php
        $conn = new mysqli('localhost', 'user', 'pw', 'dbname');

        $sql = $conn->query('SELECT * FROM audio');
        while($data = $sql->fetch_array()) {
        $id = $data['id'];
            echo '
                <tr>
                    <td>'.$data['subject'].'</td>
                    <td><a href="audioplayer.php?id='.$data['id'].'">'.$data['title'].'</a></td>
                    <td>'.$data['author'].'</td>
                </tr>
            ';
        }
    ?>
Detail page:

Code: Select all

    <!DOCTYPE html>
     <html>
      <head>
      </head>

    <body>

    <?php
 	$conn = new mysqli('localhost', 'USER', 'PW', '|DB');
  
    ?>	

    <?php

        $id = $_GET['id'];

        $row = $id;

        $result = mysqli_query($con, "SELECT * FROM audio WHERE id = $id");

        while($row = mysqli_fetch_array($sqli)){


    ?> <h2><?php echo $row['title']; ?> </h2>

    <p>Speaker: <?php echo $row['author']; ?> </p>

    <p><?php echo $row['date']; ?> </p>

    <p><span style="font-style: italic">Category: <?php echo $row['subject']; ?> </span></p><br />
    <audio controls>
    <source src="http://media.xxxxx.org/<?php echo $row['audio_location']; ?>" type="audio/mp3">

    </audio>
	<?php }; ?>

      </body>
     </html>

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 761
Joined: Mon Feb 22, 2016 5:52 pm

Mon Nov 12, 2018 2:21 pm

Compare the lines:

Code: Select all

$conn = new mysqli('localhost', 'USER', 'PW', '|DB');
and

Code: Select all

$result = mysqli_query($con, "SELECT * FROM audio WHERE id = $id");

Post Reply