mysql+php:如何按原样存储 html 字符串
我需要像这样存储 s 字符串,在 mysql 中按原样存储,
member of the ruling <a href="/tets/Polish_United_Workers%27_Party"
但在 mysql 中,%27 与 ' char 一致,
我怎样才能使 sql 保持原样的字符串?
更新:
我将文本
var string = 'member of the ruling <a href="/tets/Polish_United_Workers%27_Party"'
从 javascript 发送到 php (也许问题就在这里?)
$.ajax({
url: myurl,
async:false,
data: "text="+string,
type: "POST",
success: function( data ) {....etc...
接收 js 调用的 php 文件上的 sql 查询部分
text = addslashes($_POST["text"])
i need to store s tring like this, AS IS in mysql
member of the ruling <a href="/tets/Polish_United_Workers%27_Party"
but in mysql the %27 is concerted to ' char
how can i keep the sql respecting exactly the string as is?
UPDATE:
I send the text
var string = 'member of the ruling <a href="/tets/Polish_United_Workers%27_Party"'
from javascript to php (maybe the problem is here?)
$.ajax({
url: myurl,
async:false,
data: "text="+string,
type: "POST",
success: function( data ) {....etc...
parte of the sql query on the php file receiving the js call
text = addslashes($_POST["text"])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
替代方法并让 jquery 为您处理编码。当您将其插入数据库时,您可以在插入之前对其调用
mysql_real_escape_string
,这样您就不会受到 SQL 注入的攻击,并且所有内容都会正确转义,或使用更多现代数据库抽象层(PDO)。use
instead and let jquery handle the encoding for you. when you insert it to your DB you can call
mysql_real_escape_string
on it before inserting it so that you're not vulnerable to SQL injection and everything gets escaped properly, or use a more modern database abstraction layer (PDO).之前添加
escape(string)
我的错,我忽略了它,是的,解决方案是在提交到 php arrggg
my bad, i overlooked it and YEs the solution was to add
escape(string)
before submitting to phparrrhggg