doudu9148 2016-08-25 12:41
浏览 35

JS / PHP / MySQL成功但未插入

I have a array containing objects and I want to store these objects into my MySQL DB. At the beginning it worked quite fine, but suddenly it stopped working even though it did not make any changes to the code or the DB.

The array of object looks as follows: var geocoded = [{zip: 1234, place: "XY", country: "XY", lat: "123.123", lng: "123.123"}, ...];

I use the following JS code to iterate over the array and post each object to the DB. kiter is the iterator I use and is defined as geocoded.length - 1

function postPlaces(data, kiter) {

  if (kiter >= 0) {
    $.post("api/placessave.php", 
      data[kiter],
      function(data, status){
        kiter--;
        postPlaces(geocoded, kiter);
        console.log(data + '.............' + status);
      }
    );
  } else {
        //statusUpdate(id);
  }
}

placessave.php looks as follows:

<?php
 define('HOST','localhost');
 define('USERNAME', 'root');
 define('PASSWORD','*****');
 define('DB','****');

 $con = mysqli_connect(HOST,USERNAME,PASSWORD,DB);

 $zip = $_POST['zip'];
 $place = $_POST['place'];
 $country = $_POST['country'];
 $lat = $_POST['lat'];
 $lng = $_POST['lng'];

 $sql = "insert ignore into places (zip, place, country, lat, lng) values ($zip, '$place', '$country', '$lat', '$lng')";

 if(mysqli_query($con, $sql)){
 echo "success";
 }

 mysqli_close($con);
?>

I use INSERT IGNORE because duplicates may exist but an update is not needed. The interesting part is, that everything works quite nice I also get a Success on every query but nothing is stored to the DB.

  • 写回答

3条回答 默认 最新

  • dongshuo1856 2016-08-25 12:46
    关注

    Insert Query you have to change like this. You have Missed Quotes around the values

    Replace

    $sql = "insert ignore into places (zip, place, country, lat, lng) values ($zip, '$place', '$country', '$lat', '$lng')";
    

    With

    $sql = "insert ignore into places (zip, place, country, lat, lng) values ('".$zip."', '".$place."', '".$country."', '".$lat."', '".$lng."')";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集