dongliang1893 2013-04-22 07:35
浏览 77

MySQL查询发送成功,但数据库字段保持空白

The following 2 queries are the result of an echo in php:

UPDATE glymping_userdata
SET current_location_gps = '51.9171115;4.484812'
WHERE id = 1

and

UPDATE glymping_user_has_appointments
SET status = 'enroute',
start_location_gps = '51.9171115;4.484812'
WHERE userId = 1
AND appointmentId = 47

Both queries work when entered manually in the database and all fields are filled correctly. When I let the php file run the queries, the queries are like shown above, but the "start_location_gps" and the "current_location_gps" are empty.

The values in the queries are strings and the database fields are a varchar(30). Yet the fields in the database are empty.

The location value is received from a post method.

Does anyone knows what I am forgetting or doing wrong?

EDIT:

php example

public function SendQuery($query)
{
    $results = $this->mysqli->query($query);
    return $results;
}

public function UpdateUserLocation($currentLocationGps)
{
    $query = "UPDATE ".DB_PREFIX."userdata
                SET current_location_gps = '{$currentLocationGps}'
                WHERE id = ".$this->userId;
    //echo $query;
    $this->db->SendQuery($query);
}
  • 写回答

1条回答 默认 最新

  • dousi2553 2013-04-22 07:56
    关注

    Your current code doesn't check the return value of mysqli_query; the query might fail "silently". It could also be that the query does not affect any records in the database becaue of wrong values in the WHERE clause.
    Try it with

    if ( !$this->db->SendQuery($query) ) {
      // query failed: syntax error, connection lost, access denied,duplicate entries, ...
      trigger_error($this->mysqli->error);
    }
    else {
      if ( 0 < $this->mysqli->affected_rows ) {
        // WHERE clause doesn't match any record, no values changed, ...
        trigger_error('no rows affected');
      }
    }
    

    Your query might also be prone to sql injections, please check http://php.net/manual/en/security.database.sql-injection.php

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?