gpt4 book ai didi

php - Mysql Insert Error 找不到问题

转载 作者:行者123 更新时间:2023-12-01 00:11:33 29 4
gpt4 key购买 nike

您好,我正在使用下面的代码,并且已经使用了很多次,但不明白为什么这不起作用,我认为这只是无法看到问题的情况,所以我如果其他人可以查看并找出问题,我们将不胜感激。

这是我遇到的错误;

You have an error in your SQL syntax; check the manual that corresponds to
your MySQL server version for the right syntax to use near
'Azur', 'Antibes', '43.5624', '7.1278', '', '', 'Europe/Paris', 'EU', '', 'Amadeu'
at line 6

代码如下:

  if (!isset($params['i'])) $params['i'] = '82.150.248.29';

$query = 'https://geoip.maxmind.com/e?' . http_build_query($params);

$omni_keys =
array(
'country_code',
'country_name',
'region_code',
'region_name',
'city_name',
'latitude',
'longitude',
'metro_code',
'area_code',
'time_zone',
'continent_code',
'postal_code',
'isp_name',
'organization_name',
'domain',
'as_number',
'netspeed',
'user_type',
'accuracy_radius',
'country_confidence',
'city_confidence',
'region_confidence',
'postal_confidence',
'error'
);

$curl = curl_init();
curl_setopt_array( $curl,
array(
CURLOPT_URL => $query,
CURLOPT_USERAGENT => 'MaxMind PHP Sample',
CURLOPT_RETURNTRANSFER => true
)
);

$resp = curl_exec($curl);

if (curl_errno($curl)) {
throw new Exception('GeoIP Request Failed');
}

$omni_values = str_getcsv($resp);
$omni = array_combine( $omni_keys, $omni_values);

//print_r($omni_values);

$country_code= $omni['country_code'];
$country_name= $omni['country_name'];
$region_code= $omni['region_code'];
$region_name= $omni['region_name'];
$city_name= $omni['city_name'];
$latitude= $omni['latitude'];

$longitude= $omni['longitude'];
$metro_code= $omni['metro_code'];
$area_code= $omni['area_code'];
$time_zone= $omni['time_zone'];
$continent_code= $omni['continent_code'];
$postal_code= $omni['postal_code'];

$isp_name= $omni['isp_name'];
$organization_name= $omni['organization_name'];
$domain= $omni['domain'];
$as_number= $omni['as_number'];
$netspeed= $omni['netspeed'];
$user_type= $omni['user_type'];

$accuracy_radius= $omni['accuracy_radius'];
$country_confidence= $omni['country_confidence'];
$city_confidence = $omni['city_confidence'];
$region_confidence= $omni['region_confidence'];
$postal_confidence= $omni['postal_confidence'];
$error= $omni['error'];

//Insert to MasterTable
mysql_query("INSERT INTO mastertable
(country_code, country_name, region_code, region_name, city_name, latitude, longitude, metro_code, area_code, time_zone, continent, postal_code, isp_name, organisation, domain_name, as_number, netspeed, user_type, accuracy_radius, country_confidence_factor, city_confidence_factor, region_confidence_factor, postal_code_confidence_factor, error)

VALUES

('$country_code', '$country_name', '$region_code', '$region_name', '$city_name', '$latitude', '$longitude', '$metro_code', '$area_code', '$time_zone', '$continent_code', '$postal_code', '$isp_name', '$organization_name', '$domain', '$as_number', '$netspeed', '$user_type', '$accuracy_radius', '$country_confidence', '$city_confidence', '$region_confidence', '$postal_confidence', '$error' ) ")
or die(mysql_error());

最佳答案

这是因为您需要在插入之前对数据进行转义!例如,您似乎尝试插入 'cotes d'azur''cotes d'azur 没有转义

关于php - Mysql Insert Error 找不到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16081829/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com