endorush Posted October 28, 2020 Share Posted October 28, 2020 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> Quote Link to comment https://forums.phpfreaks.com/topic/311652-inserting-variable-into-iframe/ Share on other sites More sharing options...
cyberRobot Posted October 28, 2020 Share Posted October 28, 2020 Try adding echo before the variable. Quote Link to comment https://forums.phpfreaks.com/topic/311652-inserting-variable-into-iframe/#findComment-1582114 Share on other sites More sharing options...
gw1500se Posted October 28, 2020 Share Posted October 28, 2020 Try this: <?php echo "<iframe width=\"420\" height=\"315\" src=\"$address\">"; echo "</iframe>"; ?> I am assuming you have echo'ed $address to make sure it is what you expect. Quote Link to comment https://forums.phpfreaks.com/topic/311652-inserting-variable-into-iframe/#findComment-1582115 Share on other sites More sharing options...
endorush Posted October 28, 2020 Author Share Posted October 28, 2020 echo before the variable... ooops!!! lol its working now.... THANKS!!!! Quote Link to comment https://forums.phpfreaks.com/topic/311652-inserting-variable-into-iframe/#findComment-1582116 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.