MySql插入0而不是我的值

时间:2018-02-25 15:39:26

标签: php mysql insert

当我尝试在MySQL中发送此查询时,它不起作用。

这是查询:

INSERT INTO odds_table 
(ID, 
DataOra, 
League, 
TeamHome, 
TeamAway, 
SpreadNowHome, 
SpreadNowAway, 
OddsNowHome, 
OddsNowAway, 
SpreadOpenHome, 
SpreadOpenAway, 
OddsOpenHome, 
OddsOpenAway, 
TotalLineNow, 
TotalLineOpen, 
OverNow, 
UnderNow, 
OverOpen, 
UnderOpen) 
VALUES 
(NULL, 
DataOra='25/02/2018 16:00', 
League='Belgium First Division B', 
TeamHome='KFCO Beerschot Wilrijk', 
TeamAway='Lierse SK', 
SpreadNowHome='-0.5', 
SpreadNowAway='0.5', 
OddsNowHome='1.82', 
OddsNowAway='2.08', 
SpreadOpenHome='-0.5', 
SpreadOpenAway='0.5', 
OddsOpenHome='1.85', 
OddsOpenAway='1.99', 
TotalLineNow='2.5', 
TotalLineOpen='2.5', 
OverNow='1.90', 
UnderNow='1.98', 
OverOpen='1.96', 
UnderOpen='1.86')

在php中插入如下:

mysqli_query($con, "INSERT INTO odds_table (ID, DataOra, League, TeamHome, TeamAway, SpreadNowHome, SpreadNowAway, OddsNowHome, OddsNowAway, SpreadOpenHome, SpreadOpenAway, OddsOpenHome, OddsOpenAway, TotalLineNow, TotalLineOpen, OverNow, UnderNow, OverOpen, UnderOpen) VALUES (NULL, DataOra='$DataOra', League='$League', TeamHome='$TeamHome', TeamAway='$TeamAway', SpreadNowHome='$SpreadNowHome', SpreadNowAway='$SpreadNowAway', OddsNowHome='$OddsNowHome', OddsNowAway='$OddsNowAway', SpreadOpenHome='$SpreadOpenHome', SpreadOpenAway='$SpreadOpenAway', OddsOpenHome='$OddsOpenHome', OddsOpenAway='$OddsOpenAway', TotalLineNow='$TotalLineNow', TotalLineOpen='$TotalLineOpen', OverNow='$OverNow', UnderNow='$UnderNow', OverOpen='$OverOpen', UnderOpen='$UnderOpen')");

我尝试了其他解决方案,但没有任何效果。 表中浮点数的值是十进制(5,2)。 我怎么解决?

聚苯乙烯。单峰不是问题。

2 个答案:

答案 0 :(得分:2)

你在VALUES中使用的UPDATE语法没有“SET”,这是有效的。

您可以添加SET方法,也可以移除Column_name='$variable'的所有实例,并将其替换为'$variable'

旁注:如果有任何MySQL会抱怨的字符,例如撇号,那么你需要将其转义,因为那将是一个SQL注入。在任何一种情况下,您都应该对查询进行参数化。

手册https://dev.mysql.com/doc/refman/5.7/en/insert.html中的示例:

使用标准INSERT / VALUES:

INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
    [INTO] tbl_name
    [PARTITION (partition_name [, partition_name] ...)]
    [(col_name [, col_name] ...)]
    {VALUES | VALUE} (value_list) [, (value_list)] ...
    [ON DUPLICATE KEY UPDATE assignment_list]

使用“SET”:

INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
    [INTO] tbl_name
    [PARTITION (partition_name [, partition_name] ...)]
    SET assignment_list
    [ON DUPLICATE KEY UPDATE assignment_list]

但是,如果您还没有这样做,则应该使用准备好的声明。

使用mysqli_error($con)会向您显示错误。

答案 1 :(得分:0)

请尝试以下查询

INSERT INTO odds_table (ID, DataOra, League, TeamHome, TeamAway, 
SpreadNowHome, SpreadNowAway, OddsNowHome, OddsNowAway, SpreadOpenHome, 
SpreadOpenAway, OddsOpenHome, OddsOpenAway, TotalLineNow, TotalLineOpen, 
OverNow, UnderNow, OverOpen, UnderOpen) VALUES (NULL, '25/02/2018 16:00', 
'Belgium First Division B', 'KFCO Beerschot Wilrijk', 'Lierse SK', '-0.5', 
'0.5', '1.82', '2.08', '-0.5', '0.5', '1.85', '1.99', '2.5', '2.5', '1.90', 
'1.98', '1.96', '1.86')