Mithu
Mithu

Reputation: 655

How to Save Special Character to Mysql Database in PHP

I am saving banner url in mysql php taking the url from a textbox input by insert statement but it is saving the url as below

<a href="https://www.mywiuir.com/ptp/?r=pro2"><img src="https://i.imgur.com/PLMoHfN.gif" width="468" height="60"></a>

sign like < or </ or > /> etc are escaping and is being saved as &lt; &gt; how can i save this as < or </ or > />

below is my insert statement where $banner_url is getting from a textbox input

$set = array("user_id" => $user_info['id'],"title" => $item_price['days'].' Days',"url" => 
        $banner_url, "start" => $start_date,"expires" => $expires,"expire_int" => $expire_int);
$insert = $db->insert("login_ads", $set);

this is my form

    <form method="post" id="loginadform" onsubmit="return submitform(this.id);">
    <input style="margin-top:10px; background-color:white;" type="text" id="banner_url" name="banner_url" placeholder="Enter Banner Url" required>

and i am getting the banner input with below code

$banner_url = $input->pc['banner_url'];

Upvotes: 0

Views: 1117

Answers (1)

Dhairya Lakhera
Dhairya Lakhera

Reputation: 4808

It good practise to insert HTML characters inside DB as HTML entities. However you may fetch data using html_entity_decode. It will convert HTML entities to their corresponding characters.

Upvotes: 1

Related Questions