简体   繁体   中英

Insert html content to mysql table

I need to insert html content to mysql table.but script cut part of html content. Html content is as below.

        <div data-plugin-lightbox data-plugin-options='{"delegate": "a", "type": "image", "gallery": {"enabled": true}}'>

i cannot upload all content.mysql table has Only

 <div data-plugin-lightbox data-plugin-options={"

How can i insert any html content to mysql table.

Seems a double quote related issue .. you should escape the double quote for json

<div data-plugin-lightbox data-plugin-options='{\"delegate\": \"a\", \"type\":    .......

or the issue could be related to your string assignment in php

the assignment

$sql = "< <div data-plugin-lightbox data-plugin-options='{"delegate": " 

break on the second double quotes

HTML tegs可以用纯文本插入到mysql中。但是你应该回显你正确插入的内容

use htmlspecialchars($str) before you store in DB.

and use htmlspecialchars_decode($str) after reading from DB.

Try using htmlspecialchars() on the string to put into the DB, and then, when pulling it back out, use htmlspecialchars_decode(). Might make a difference.

You should always escape your strings before using them in SQL queries, to avoid the kind of problems you have here and for security reasons .

PHP's mysqli extenstion comes with the mysqli_real_escape_string that is here just for this purpose and respects the connection's charset:

Object oriented style:

$var = $mysqli->real_escape_string($var);

Procedural style:

$var = mysqli_real_escape_string($db_link, $var);

I found a solution. Reason is ' & quot ; '. Used this to avoid var NewString = text.replace(/&/g, "xxx");

thank you all

htmlentities($message,ENT_QUOTES );

It works for me for both double and single quotes in HTMl.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM