Search code examples
phpmysqlyoutubeembeddisplay

Display Youtube Video from database in PHP


I found a weird occur in my code. I display youtube video from my database on my PHP page. I saved youtube video id in my database. All youtube videos working perfectly except one (https://www.youtube.com/watch?v=_oFsdDHuhQQ&feature=youtu.be) this video not running on my code. I check this video running on WordPress but not run in this method. I don't know why it's happening maybe video id starting from "_"(underscore) Can anyone help?

<div class="row">
            <?php
                $video_query="select * FROM care_class_topic_file_upload WHERE care_topic_id='$_GET[care_topic_id]' AND care_class_topic_file_type=1";
                $video_result= mysqli_query($con,$video_query);
                 while($row_video = mysqli_fetch_assoc($video_result))
                 {
                ?>
            <div class="col-6 col-sm-3 col-md-4" style="padding:10px;">
                <div class="embed-responsive embed-responsive-16by9">
                  <?$page="https://www.youtube.com/embed/$row_video[care_class_topic_file_video_url]";?>
                    <iframe class="embed-responsive-item" src=<? echo $page; ?> frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
                </div>
            </div>
        
            <?php
                 }
            ?>
            
        </div>

Solution

  • Are you including &feature=youtu.be to your link? https://www.youtube.com/embed/_oFsdDHuhQQ seems to work... can you try your code with no additional parameters other than the YouTube ID only please?