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.

    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能