我收到以下错误:
PHP Parse error: parse error, unexpected '*', expecting '}' in /var/www/html/dev/562.ajax.php on line 278, referer: 562.shp.php?cut=8161
如果我们转到文件562.ajax.php中的第278行,我们会看到以下内容:
$sql = 'insert into NKW.EDI_CARTON_LI ' .
'(EDI_SHIPMENT, EDI_CARTON, CORP_CODE, EDI_TOTALQTY, EDI_PRICE, ' .
'EDI_AMOUNT, EDI_UNITWEIGHT, EDI_WEIGHT, PICKTKT_NO, SEQ_ORDER_NO, ' .
'ORDER_NO, CUST_NO, RECORD_NO, STYLE, COLOR_NO, ' .
'COLOR_ABBR, SIZE_NO, SIZE_NAME) ' .
"values ($shipment, $carton, '$division', $quantity, '$price', " .
"'{$quantity * $price}', '{$weight / $quantity}', '$weight', $ticket, $sequence, " .
"'$order', '$customer', NKW.SEQ_EDI_CARTON_LI.nextval, '$style', '$color', " .
"'$abbr', '$ratio', 'ALL')";
error_log($sql);
if (SQLExec($dbc, $sql))
return array(1, 'System error in ' . __FILE__ . ' @ ' . __LINE__);
有问题的代码是(第278行):“'{$ quantity * $ price}',
现在他显然是在尝试根据数量生成价格总额,为什么PHP不这样呢?它对我来说是正确的。我怀疑我会有一个类似的错误,但在此之后立即对重量进行划分。是否有一些逃避角色或我需要在这里添加的东西?
答案 0 :(得分:1)
PHP不允许使用简单的字符串替换进行变量算术。这是相同的代码而不会产生语法错误:
$sql = 'insert into NKW.EDI_CARTON_LI ' .
'(EDI_SHIPMENT, EDI_CARTON, CORP_CODE, EDI_TOTALQTY, EDI_PRICE, ' .
'EDI_AMOUNT, EDI_UNITWEIGHT, EDI_WEIGHT, PICKTKT_NO, SEQ_ORDER_NO, ' .
'ORDER_NO, CUST_NO, RECORD_NO, STYLE, COLOR_NO, ' .
'COLOR_ABBR, SIZE_NO, SIZE_NAME) ' .
"values ($shipment, $carton, '$division', $quantity, '$price', " .
"'" . $quantity * $price ."', '" . $weight / $quantity . "', '$weight', $ticket, $sequence, " .
"'$order', '$customer', NKW.SEQ_EDI_CARTON_LI.nextval, '$style', '$color', " .
"'$abbr', '$ratio', 'ALL')";
观察:
"'" . $quantity * $price ."', '" . $weight / $quantity .
我结束了引用,让PHP直接评估表达式。是的,像这样的大型SQL查询很乱。
答案 1 :(得分:0)
我测试了你发布的代码并看到了同样的错误。这应该有效:
$sql = 'insert into NKW.EDI_CARTON_LI ' .
'(EDI_SHIPMENT, EDI_CARTON, CORP_CODE, EDI_TOTALQTY, EDI_PRICE, ' .
'EDI_AMOUNT, EDI_UNITWEIGHT, EDI_WEIGHT, PICKTKT_NO, SEQ_ORDER_NO, ' .
'ORDER_NO, CUST_NO, RECORD_NO, STYLE, COLOR_NO, ' .
'COLOR_ABBR, SIZE_NO, SIZE_NAME) ' .
"values ($shipment, $carton, '$division', $quantity, '$price', '" .
$quantity * $price ."', '" . $weight / $quantity . "', '$weight', $ticket, $sequence, " .
"'$order', '$customer', NKW.SEQ_EDI_CARTON_LI.nextval, '$style', '$color', " .
"'$abbr', '$ratio', 'ALL')";
error_log($sql);
答案 2 :(得分:0)
您可以将结果保存到一个'string of string'变量中,然后在字符串中使用该结果的dhe值
$total = $quantity * $price
"{$total}...