1

我有一个小问题。我已经编写了这段代码来将值添加到 mysql 数据库中,但是当我运行代码时出现错误。有谁能够帮我?

编码:

$fel = $mysqli->query("INSERT INTO deleted (uid,buy_type,prop_type,district,street,room_min,room_max,price_min,price_max,condition_type,heat_type,lift_type,parking_type,type_of_del,when)  
                            VALUES ('".$mysqli->real_escape_string($letomb['uid'])."',
                                    '".$mysqli->real_escape_string($letomb['buy_type'])."',
                                    '".$mysqli->real_escape_string($letomb['prop_type'])."',
                                    '".$mysqli->real_escape_string($letomb['district'])."',
                                    '".$mysqli->real_escape_string($letomb['street'])."',
                                    '".$mysqli->real_escape_string($letomb['room_min'])."',
                                    '".$mysqli->real_escape_string($letomb['room_max'])."',
                                    '".$mysqli->real_escape_string($letomb['price_min'])."',
                                    '".$mysqli->real_escape_string($letomb['price_max'])."',
                                    '".$mysqli->real_escape_string($letomb['condition_type'])."',
                                    '".$mysqli->real_escape_string($letomb['heat_type'])."',
                                    '".$mysqli->real_escape_string($letomb['lift_type'])."',
                                    '".$mysqli->real_escape_string($letomb['parking_type']).",
                                    '".$mysqli->real_escape_string($type_of_del)."', 
                                    now())") or die($mysqli->error);

错误:

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 'when) VALUES ('3', 'kiado', 'lakas', '1'' at line 1
4

2 回答 2

2

WHEN是一个保留字。将其括在反引号中应该可以解决您的问题,因为它将被视为标识符

`when`
于 2013-07-14T06:41:04.260 回答
1

您应该在列名周围使用反引号。when是一个 MySQL 关键字,因此它被错误地解释。至少在 . 周围使用反引号when

于 2013-07-14T06:43:03.003 回答