php - 我在我的代码数组中不断收到此错误( [0] => 01000 [1] => 1265 [2] => 第 1 行的列 'lon' 的数据被截断)
问题描述
这是我的代码,错误不断出现。一切都符合表格,但我仍然得到同样的错误。我已经尝试过,在 sql 表中,lon 和 lan 是基于数字的,所以我不知道这是否是问题所在:
<?php
$n = $_POST["name"];
$t = $_POST["type"];
$c = $_POST["country"];
$r = $_POST["region"];
$lon = $_POST["longitude"];
$lat = $_POST["latitude"];
$des = $_POST["description"];
$conn = new PDO("mysql:host=localhost;dbname=hjaved;", "hjaved","queeTh1d");
$conn->query("INSERT INTO pointsofinterest (name, type, country,
region, lon, lat, description) VALUES ('$n', '$t', '$c', '$r',
'$lon',
'$lat', '$des')");
print_r($conn->errorinfo());
?>
这是 shcema 表:
ID 名称 类型 国家 地区 lon lat 描述
解决方案
这是一个例子,如何摆脱 mysql 注入,使用准备 + 执行方法(来自 PDO 对象)
<?php
$conn = new PDO("mysql:host=localhost;dbname=hjaved;", "hjaved","queeTh1d");
$conn->prepare("
INSERT INTO pointsofinterest (
`name`,
`type`,
`country`,
`region`,
`lon`,
`lat`,
`description`
) VALUES (
:name,
:type,
:country,
:region,
:lon,
:lat,
:description
);");
$conn->execute(array(
':name' => $_POST["name"],
':type' => $_POST["type"],
':country' => $_POST["country"],
':region' => $_POST["region"],
':lon' => $_POST["longitude"],
':lat' => $_POST["latitude"],
':description' => $_POST["description"],
));
print_r($conn->errorinfo());
推荐阅读
- react-native - FlatList 没有渲染它显示除 FlatList 之外的任何内容
- javascript - 如何在展开可折叠 div 时调用 API 并使用 AngularJS 用 API 响应填充其内容?
- laravel - 使用 json_decode 时为 foreach() 提供的参数无效
- c# - 使用带有 Pipedream SSE API 的 ServiceStack ServerEventsClient 时出现 404 未找到错误
- c++ - 使用自定义比较器定义映射,其中值数据结构也具有自定义比较器
- ruby-on-rails - 根据rails中另一个下拉列表的值生成下拉列表值
- json - 从 json api 角度获取对象中的对象不显示
- java - 如何使用 JavaFX 从树视图中的绝对路径中获取文件夹或文件名?
- c++ - 在 unordered_map 中使用浮点数作为键的好方法
- reactjs - 如何在反应日期选择器中动态禁用天数