Jump to content

Inserting variable into Iframe


endorush

Recommended Posts

I'm having problem with this code. It's supposed to pull a  link from a database and feed it into an iframe src to make the video display on screen.

I'm getting a white box...

It seems like the "address" variable is getting dropped or something, out of scope?

here is the code:

 

<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */

$link = mysqli_connect("localhost", "root", "Mm62Tic8FH", "music");

$rand_num;
$rowcount;

// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}

// Attempt select query execution
$sql = "SELECT * FROM songs";


if($result = mysqli_query($link, $sql)){ // query results stored in "result"
    if(mysqli_num_rows($result) > 0){
        $rowcount = mysqli_num_rows($result);
        $rand_num = rand(0,$rowcount - 1);
        $address = "5";
        echo "<table>";
            
        while($row = mysqli_fetch_array($result)){
            echo "<tr>";
                echo "<td>" . $row['artist_name'] . "</td>";
                echo "<td>" . $row['song_name'] . "</td>";
                echo "<td>" . $row['url'] . "</td>";
                echo "<td>" . $row['item_id'] . "</td>";
                echo "<td>" . $rand_num;

            echo "</tr>"; 

            if ($rand_num == $row['item_id']) {
                $address = "https://www.youtube.com/embed/". $row['url'];
            }

            echo "----".$address."----";

        }
        echo "</table>";
        // Free result set
        mysqli_free_result($result);
    } else{
        echo "No records matching your query were found.";
    }
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
 
// Close connection
mysqli_close($link);

?>

   
<iframe width="420" height="315"
    src=<?php  $address ?>>
</iframe> 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.