Php + mysql how to store html code to the database? Php + mysql how to store html code to the database?
What should I pay attention? What type is used for database fields? How does php handle html code?
Hello world
'; // Database tablepart_name | html_codehello | ?? ?>
Reply to discussion (solution)
The field type is text type, which can be stored directly.
Tinytext can contain a maximum of 255 (2 ^ 8-1) characters.
Text can contain a maximum of 65535 (2 ^ 16-1) characters.
Mediumtext can contain a maximum of 16777215 (2 ^ 24-1) characters.
Longtext can contain a maximum of 4294967295 (2 ^ 32-1) characters.
Select based on situation
There are two positive solutions upstairs,
Supplement:
1. Save the new string to the database.
2. the field must be of the string type, including text and varchar (the length must be sufficient.
3. when you read data from the database, remember to use the htmlspecialchars function for processing. Otherwise, the received string will be html code.