0

我有以下mysql语句:

INSERT INTO rates_try (`Weight`, `length`, `height`, `Min`, `100`, `200`, `300`) VALUES (1000,0.1,2.3,1,2,3,4);

这给出了错误:

未创建行。检查您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“插入查询”附近使用正确的语法 INSERT INTO rates_try ( Weight, length, height, Min, 100, 200, 300) VALUES (1500,2.31,3.5,1,0,0,0);

表结构为:

rates_try ( `Weight` int(11), 
            `length` double, 
            `height` double, 
            `Min` double, 
            `100` double, 
            `200` double, 
            `300` double )

我不确定语法有什么问题,我知道它很可能与作为数字的列有关,如果这是导致它的问题,我将不得不在名称中添加一些内容,以便它们不仅仅是数字,而是我想先检查一下情况是否如此。

创建语句的 php 代码

$insertquery = "INSERT INTO rates_{$tablename} (`Weight`, `length`, `height`, `Min`";
                foreach ($titles as $title){
                    if (empty($title) ){

                    }else{
                        $insertquery .= ", `" . $title . "`";
                        $counter++;
                    }
                }
                $insertquery .=  ") VALUES (".$row['weight'].",".$row['cbm_min'].",".$row['cbm_max'].",".$value;
                $a = 0;
                while ($a < $counter){
                    $newvalue = $array[$a][$i];
                    if (empty($newvalue)){
                        $newvalue = 0;
                    }
                    $insertquery .= ",". $newvalue;
                    $a++;
                }
                $insertquery .= ");";

                echo $insertquery. "<br/>";
                $queryResult = mysqli_query($con, insertquery);
4

2 回答 2

5

$queryResult = mysqli_query($con, insertquery);

你现在能看到吗?

$前面少了一个insertquery

于 2013-09-05T10:17:43.103 回答
0

This is an interesting one, as you have actually followed the rules about using backticks to surround column names - and according to the document I just checked, your column names ARE indeed valid:

Identifiers may begin with a digit but unless quoted may not consist solely of digits.

On that note, while MySQL identifiers on Windows are not case sensetive, you will find that on Linux, they ARE. Are you sure that you haven't missed an upper or lower case somewhere? Your first column uses an upper case to start, but none of the others do.

I will however say that using column names that must be back-ticked is generally a BAD idea. Use something that doesn't need special care each and every time you refer to it.

于 2013-09-05T10:14:50.583 回答