您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

MySQL和PHP-插入NULL而不是空字符串

MySQL和PHP-插入NULL而不是空字符串

要将NULL传递给MysqL,只需执行此操作。

INSERT INTO table (field,field2) VALUES (NULL,3)

因此,在您的代码中,检查if $intLat, $intLngempty,如果是,请使用NULL代替'$intLat''$intLng'

$intLat = !empty($intLat) ? "'$intLat'" : "NULL";
$intLng = !empty($intLng) ? "'$intLng'" : "NULL";

$query = "INSERT INTO data (notes, id, filesUploaded, lat, lng, intLat, intLng)
          VALUES ('$notes', '$id', TRIM('$imageUploaded'), '$lat', '$long', 
                  $intLat, $intLng)";
php 2022/1/1 18:14:09 有458人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶