Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6605155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:15:01+00:00 2026-05-25T19:15:01+00:00

I am using codeigniter and at the moment I have a bit of the

  • 0

I am using codeigniter and at the moment I have a bit of the problem. When I insert iframe (from the youtube) into db in the view file I get row code like this:

<iframe width="420" height="315" src="http://www.youtube.com/embed/aWvcNkRJhHw" frameborder="0" allowfullscreen></iframe>

How to insert iframe into db and display it properly?

EDITED PART:

Form for inserting:

  <h3>Create News</h3>
<?php echo form_open('news/create_news') ?>
<label for="title">Title</label><input type="text" name="title" class="inputBox" id="title"><br>
<label for="body">Text</label><textarea name="body" class="inputBox" id="body" rows="5"></textarea>
<label for="datepicker">Date</label><input type="text" name="date" class="inputBox" id="datepicker">
<input type="submit" name="submit" value="Create" class="submit" />
<input type="reset" class="button standard" value="Clear" />
<?php echo form_close() ?>

Function for inserting:

    function create_news()
    {
         $data = array(
   'title' => $_POST['title'],
   'body' => $_POST['body'],
    'date' => $_POST['date']         
);
$this->db->insert('news', $data); 
    }

I tried to insert iframe from youtube (embed video) but it does not work very well. When I load view file I just get text instead of video ().

Controller function:

function news() {
    $this->load->helper('text');
    if ($this->session->userdata('is_logged_in') == true) {
        $q = $this->news_model->get_all();
        if ($q == false) {
            $data['np'] = 'There is no news at the moment.';
        } else {
            $data['news'] = $q;
        }
        $this->pagg();                      
        $data['main_content'] = 'admin_news';
        $data['title'] = 'Admin News';
        $this->load->view('admin/template', $data);                     
    } else {
        $this->index();
    }
}

View file:

  <div id="news">
<?php if (isset($np)) { echo '<p>' . $np . '</p>'; } ?>
<?php if (isset($news)) : ?>    
    <?php foreach ($news as $row) : ?>
    <div class="borderBott col_12">
            <h3><a href="<?php echo base_url() ?>admin/news_update/<?php echo $row['title'] . "/" . $row['id_news'] ?>" ><?php echo $row['title'] ?></a></h3>
            <p class="<?php echo alternator('par', 'nepar') ?>"><?php echo word_limiter($row['body'], 50); ?></p>
            <p>Date written: <?php echo $row['date'] ?></p>
            <a href="#" class="delete" id="<?php echo $row['id_news'] ?>">Delete News</a>            
        </div>
    <?php endforeach; ?>  
<?php endif; ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:15:02+00:00Added an answer on May 25, 2026 at 7:15 pm

    As NullUserException suggested, it’s not a good idea to store the whole iframe tag in your database.

    First and foremost: it’s ugly. Your storing layout dependent data in your database. NEVER do this. What if you decide you want a different default width and height? You would need to edit all existing records in your database.

    Secondly, if YouTube changes their embedded code, all your data would be rendered useless.

    IMO the correct solution would be to extract the video id from the iframe and store this in your database.

    However, if what I’m assuming is correct and you have a news post with an embedded video in it, you need to take a look at the BBCode mechanism. Your HTML is stored as plain text and hence not rendered correctly when simply outputting the value from your database. By making use of a mechanism such as BBCode, you define custom tags (generally enclosed by straight brackets ‘[]’), to be stored in your database.

    Upon showing the data again all your tags are converted back to the correct HTML and you’ll get your embedded video!

    There are a few helpers for CodeIgniter: BBCode Helper or Another BBCode Helper. (Note: these are the actual names of the helpers, I’m not trying to be funny 🙂 ).

    In my CI applications I always made use of Smarty templating engine, which also provided BBCode helpers, so I never used any of the above.

    HTH.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a problem with my codeigniter library. To transform database data into
I am using codeigniter 2 in my project and I have a problem that
i am using codeigniter. i have class Orders which with some methods like start_order(),
I am using CodeIgniter and I have two different controllers - login.php and site.php
I am using Codeigniter framework and I have a form with input fields. When
I'm using CodeIgniter (a PHP framework) to build an app, and I have an
I'm using CodeIgniter (because it's awesome) and I have something like: <?php echo anchor(/,
I am using codeigniter. My products page shows all the products we have and
at the moment im integrating ORM (doctrine) into a MVC framework (codeigniter). then it
Using Codeigniter, any numeric data returned from my MySQL database is returned as strings.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.