将本地存储密钥保存到MySQL中 [英] Saving localstorage key into MySQL

查看:243
本文介绍了将本地存储密钥保存到MySQL中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们所在的城市有一个小竞赛,我们需要使用Ajax将本地存储密钥存储到MySQL中.

We have a small competition in my town where we need to store localstorage keys into MySQL using Ajax.

通过执行此项目,我发现了一些问题.

By doing this project, I found few problems.

这是我的本地存储键和值:

This is my localstorage key and value:

键:BM

值:

 [{"id":"item-1","icon":"google.com"},
    {"id":"item-3","icon":"tumblr.com"},
    {"id":"item-5","icon":"youtube.com"}]

因此,其 id:ID,图标:URL 基本上都是随机的.

So basically its id: ID, icon: URL and both can be random.

当我使用Ajax将其存储到MySQL中时,该值更改为:

When I store this into MySQL using Ajax, the value changes to:

[{\"id\":\"item-1\",\"icon\":\"google.com\"},
{\"id\":\"item-3\",\"icon\":\"tumblr.com\"},
{\"id\":\"item-5\",\"icon\":\"youtube.com\"}]

该行的结构为longtext.我尝试过纯文本,但是相同.

The structure of that row is longtext. I've tried plain text but is the same.

我想听听经验丰富的开发人员的其他想法.

Id like to hear other thoughts from more experienced developers how would you do it.

添加并使用JSON解析的本地存储值.

The localstorage value added and parsed with JSON.

推荐答案

好像php在插入数据之前在输入中添加了斜杠.这可能是由魔术引号引起的.看看: http://php.net/manual/en/security.magicquotes. php

Looks like php is adding slashes to your input before you insert your data. This could be caused by magicquotes. Have a look at: http://php.net/manual/en/security.magicquotes.php

如果是这种情况,解决方案是关闭php中的magicquotes或使用stripslashes()

If this is the case, the solution is to either turn off magicquotes in php or to use stripslashes()

<?php

// Assuming your input is in the input variable
$input = stripslashes($_GET['input']);

mysql_query("insert into `table` ( `columnname` ) values( '" . mysql_real_escape_string($input) . "' )");

?>

这篇关于将本地存储密钥保存到MySQL中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆