简体   繁体   English

数据未插入MySQL数据库

[英]Data not inserting to MySQL database

I have my table setup as shown in the image below. 我的桌子设置如下图所示。

在此处输入图片说明

When I try and run the following code to insert the values into the database I get the error: 当我尝试运行以下代码将值插入数据库时​​,出现错误:

FAIL: INSERT INTO Betfairodds ( Horse , Back , Lay , TimeformTR )VALUES( 'Intrepid','5.5', '5.9', '0') 失败:插入BetfairoddsHorseBackLayTimeformTR )VALUES('Intrepid','5.5','5.9','0')

Would anyone be able to help, as I have tried to debug the code. 当我尝试调试代码时,任何人都可以提供帮助。

//loop through each individual card
    foreach ($getdropdown2 as $dropresults) {

 $horse = preg_replace('/\h*[^ a-zA-Z].*$/m', '', trim($dropresults->childNodes->item(8)->textContent));
 $back =  trim(GetBetween($dropresults->childNodes->item(18)->textContent, 'Back', '£'));
 $lay =  trim(GetBetween($dropresults->childNodes->item(20)->textContent, 'Lay', '£'));

    $sql = "INSERT INTO `Betfairodds` (`Horse`,`Back`,`Lay`,`TimeformTR`)VALUES( '$horse','$back', '$lay', '0')";
    $res = mysqli_query($db, $sql);
        if (!$res) {

            echo PHP_EOL . "FAIL: $sql";
                 trigger_error(mysqli_error($db), E_USER_ERROR);

        }

}

我从0删除了引号' ,因为它在架构中定义为int ,并且当然在VALUES之前添加了空格。

$sql = "INSERT INTO `Betfairodds` (`Horse`,`Back`,`Lay`,`TimeformTR`) VALUES( '$horse','$back', '$lay', 0)";

Your statement is wrong. 你的说法是错误的。 You should not put single quotes on the data fields. 您不应在数据字段上加上单引号。 so it should be like: 所以应该像这样:

$sql = "INSERT INTO `Betfairodds` (Horse,Back,Lay,TimeformTR)VALUES( '$horse','$back', '$lay', '0')";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM