dongtui2029 2017-03-11 16:14 采纳率: 0%
浏览 28

json到mysql停止工作

I am using the Gridstack library to create a dashboard. The widgets x,y,width and height can be put into a json, I am trying to save this json into MySQL.

I got the json array to enter a table in MySQL by pressing a button to work, when I was at my unviversity. When I went home, it stopped working. I am using PHP and MySQL.

The first issue was that the line below stopped working (it was fine before I went home, didn't touch code).

  $data = $_GET['name'];

Had to be changed to this:

   $data = isset($_GET['name']);

No idea why. Also the rest of the PHP stopped working. No errors, just does nothing. It isn't the script I have a problem with. All the Javascript work just fine.

Rest of the code:

 $('#save').click(function(){
      var res = _.map($('.grid-stack .grid-stack-item:visible'), function (el) {
el = $(el);
var node = el.data('_gridstack_node');
return {
    id: el.attr('data-custom-id'),
    x: node.x,
    y: node.y,
    width: node.width,
    height: node.height
};
window.location.href = "index.php?string=" + JSON.stringify(res);
});
<?php
$connect = mysqli_connect("localhost", "root", "", "widgetCollection");


 $data = isset($_GET['string']);
 //$data = $_POST['variable'];

  $array = json_decode($data, true);

  foreach((array)$array as $row) {
  $sql = "INSERT INTO grids(x, y, width, height) VALUES('".$row["x"]."', '".$row["y"]."', '".$row["width"]."', '".$row["height"]."');";

  mysqli_query($connect, $sql);
  }
  ?>
  alert(JSON.stringify(res));

  });
  • 写回答

1条回答 默认 最新

  • dqdpz60048 2017-03-11 16:48
    关注

    Isset allows you to test the existence of a key in an array, and will return a boolean.

    You should not use isset like that.

    You can write instead :

    if (isset($_GET['name'])) {
        $data = $_GET['name'] ;
    } 
    

    That will test the existence of the key 'name' in the array $_GET and, if found, will enter the 'if' condition and set the variable.

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题