CodeIgniter Forums
Database returning escaped results - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Database returning escaped results (/showthread.php?tid=15996)



Database returning escaped results - El Forum - 02-21-2009

[eluser]kevthedude[/eluser]
Hey guys,

I need some help with a little script of mine. Pretty much I have this:

Code:
$sql = "SELECT * FROM `news` WHERE `id` = ?";
            $query = $this->db->query($sql, array(intval($this->uri->segment(4))));
            if($query->num_rows() > 0)
            {
                $data = $this->backbone->required_data();
                $data['news'] = $query->row();
                die($data['news']->content);
                }
                $this->load->view("admin/news_edit", $data);
            } else {
                $this->backbone->rerror("News does not exist!", 'admin/news');
            }

Now, the returned $data['news']->content variable should return what's stored in the MySQL table:
Code:
<p><i><b>Hello world!</b></i></p>
<p>{more}</p>
<p>This is extra content that will not show on the main page.</p>

But rather returns:
Code:
Test body content
{more}
Here's some extra content that I do not want to show on the homepage.

Can't figure out how to preclude it from escaping those results. Any help would be much appreciated.


Database returning escaped results - El Forum - 02-21-2009

[eluser]TheFuzzy0ne[/eluser]
What's the collation and type of field you're storing it in?

Can you confirm the data is actually being stored correctly, and it's not being stripped as you insert it?


Database returning escaped results - El Forum - 02-21-2009

[eluser]TheFuzzy0ne[/eluser]
I'd suggest storing the data after converting it with [url="http://uk2.php.net/manual/en/function.htmlentities.php"]htmlentities()[/url] and the using [url="http://uk2.php.net/manual/en/function.html-entity-decode.php"]html_entity_decode()[/url] when you pull it out of the database. It will take up a little more space, but should recsolve your problem.


Database returning escaped results - El Forum - 02-21-2009

[eluser]kevthedude[/eluser]
[quote author="TheFuzzy0ne" date="1235278017"]What's the collation and type of field you're storing it in?

Can you confirm the data is actually being stored correctly, and it's not being stripped as you insert it?[/quote]

The collation is "text."

Woops! Just found the error too! Totally my fault, I had inserted the same information twice but one I had stripped HTML from. At a quick look I didn't notice the different IDs.


Database returning escaped results - El Forum - 02-21-2009

[eluser]TheFuzzy0ne[/eluser]
So the problem is resolved? If so, well done!