Tuesday, 15 May 2012

php - Codeigniter 2.1 - insert HTML page into database -



php - Codeigniter 2.1 - insert HTML page into database -

i trying create mini cms, user can create new page , page become part of menu. smart insert total pages database or there improve way so? having bit of problem a tag when inserting. code now:

for inserting page db:

public function strana_insert() { $this->admin_login_check(); $clear = $this->str->clean_request(); $char = array('\n', '\n'); $strana = str_replace($char, '<br>', $clear['opis']); $kljucna_rec = str_replace( ' ', '_', mb_convert_case($clear['naziv'], mb_case_lower, "utf-8") ); $data = array( 'naziv' => $clear['naziv'], 'strana' => htmlspecialchars($strana, ent_quotes , "utf-8"), 'kljucna_rec' => $kljucna_rec, 'datum_kreiranja' => date("y-m-d h:i:s") ); $this->str->save($data); $this->save_routes(); redirect('admin'); }

code clean_request function:

public function clean_request() { foreach($_post $key=>$value) : $clean[$key]=mysql_real_escape_string(trim($value)); endforeach; homecoming $clean; }

when insert page a tag next result:

<a href=\"http://www.example.com\" class=\"link_name\">www.example.com</a>

after updating page between *\ * deleted. going on here?

you can utilize codeigniter's active class insert this or utilize next method.

before inserting html info database :

$html_for_db = addslashes($html_content);

and insert $html_for_db database.

while displaying content,

echo stripcslashes($data_from_db);

stripcslashes() - un-quote string quoted addcslashes

more info : http://php.net/manual/en/function.addslashes.php

php mysql codeigniter codeigniter-2

No comments:

Post a Comment