我在这段代码中的第1行附近有语法错误:
//...
$nr = 126;
$expl = "'test'";
$da = "'2003-12-01'";
$tax = 2.5;
$cost = 100;
//Here is the error
$sql = "INSERT INTO tbl (type, nr, explan, date, tax, cost) VALUES('Example'," + $nr + ",'"+ $expl + "','" + $da + "'," + $tax + "," + $cost + ");";
这是错误日志:
Error: 103.5
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 '103.5' at line 1
我使用的是PHP版本5.6.3和MySQL版本5.6.21
我无法弄清楚,问题是什么:(
答案 0 :(得分:2)
您正在使用+
来连接字符串,这在PHP中不起作用。您必须使用.
。
可能有一些奇怪的算术会产生103.5
,就像2.5 + "," + 100
一样。将","
转换为int(1)
或其他内容的位置。