Yossi Nagar
Yossi Nagar

Reputation: 87

How to save HTML in database

I have some question about saving html code in mysql database every time when I put the charter " ' " in the database it changes to " / ".

Example: somthing like that

<p>That's my name</p>

After saving it look like this:

<p>That\'s my name</p>

what can i do? thank u all

Upvotes: 1

Views: 9470

Answers (3)

Balaji Kandasamy
Balaji Kandasamy

Reputation: 4506

You are using addslashes like escape functions in your code.

addslashes() — Quote string with slashes - http://php.net/manual/en/function.addslashes.php

stripslashes() — Un-quotes a quoted string - http://php.net/manual/en/function.stripslashes.php

Upvotes: 2

Vivek Raj
Vivek Raj

Reputation: 456

Use stripslashes to remove '\' from HTML data. Actually (') is used define string in MySql, so it ecaspe it (by putting \ in-front) in order to avoid any unintentional use.

Upvotes: 0

Quentin
Quentin

Reputation: 943470

  • Use parameterized queries to escape data going into the database
  • Use nothing else to escape data going into the database (otherwise you will double escape which can use this problem)
    • Do not use mysql_real_escape_string
    • Do not use addslashes
    • etc
  • Do not escape data coming out of the database (since that will cause this problem)
  • Make sure magic quotes are disabled (since having them turned on will escape data going into and out of the database and cause this problem).

Upvotes: 5

Related Questions