简体   繁体   English

PHP解析错误:解析错误,意外的“ *”,期望为“}”

[英]PHP Parse error: parse error, unexpected '*', expecting '}'

I am getting the following error: 我收到以下错误:

PHP Parse error:  parse error, unexpected '*', expecting '}' in /var/www/html/dev/562.ajax.php on line 278, referer: 562.shp.php?cut=8161

If we go to line 278 in file 562.ajax.php we see the following: 如果转到文件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__);

The code in question is (line 278): "'{$quantity * $price}', 有问题的代码是(第278行):“'{$ quantity * $ price}',

Now he is obviously trying to generate a price total based on quantity, why doesn't PHP like this? 现在,他显然正在尝试根据数量生成价格总和,为什么PHP不会这样? It looks correct to me. 在我看来,这是正确的。 I suspect I will have a similar error though with the division for the weight immediately after that. 我怀疑在此之后立即进行重量除法会出现类似的错误。 Is there some escape character or something I need to add here? 是否有一些转义字符或需要在此处添加的内容?

PHP doesn't allow variable arithmetic with a simple in-string substitution. PHP不允许使用简单的字符串内替换进行变量算术。 Here is the same code without generating a syntax error: 这是不产生语法错误的相同代码:

$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')";

Observe: 注意:

"'" . $quantity * $price ."', '" . $weight / $quantity . 

I ended the quote to have PHP directly evaluate the expression. 我结束了引号,以使PHP直接评估该表达式。 Yes, it's messy with a big SQL query like this. 是的,这样的大型SQL查询很混乱。

I tested out the code you posted and saw the same error. 我测试了您发布的代码,并看到了相同的错误。 This should work: 这应该工作:

$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);

You can save the result into one 'outside of string' variable and then use dhe value of that result inside the string 您可以将结果保存到一个“字符串外”变量中,然后在字符串中使用该结果的值

$total = $quantity * $price
"{$total}...

暂无
暂无

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

相关问题 解析错误:语法错误,意外的 '[',期待 ')' php - Parse error: syntax error, unexpected '[', expecting ')' php PHP解析错误:语法错误,意外的“:”,期待“;” 或者 '{' - PHP Parse error: syntax error, unexpected ':', expecting ';' or '{' 解析错误:语法错误,意外的'[',期望')',可能是PHP版本问题 - Parse error: syntax error, unexpected '[', expecting ')', possibly PHP version issue Wordpress插件PHP解析错误:语法错误,意外的“ {”,预期为“)” - Wordpress plugin PHP Parse error: syntax error, unexpected '{', expecting ')' 解析错误:语法错误,意外的';',期望的是')'(Wordpress functions.php) - Parse error: syntax error, unexpected ';', expecting ')' (Wordpress functions.php) PHP 版本 4:: 解析错误:语法错误,意外 '=',期待 ')' - PHP version 4 :: Parse error: syntax error, unexpected '=', expecting ')' PHP解析错误:语法错误,意外的T_IS_EQUAL,预期 - PHP Parse error: syntax error, unexpected T_IS_EQUAL, expecting 解析错误:解析错误,需要PHP For Loop - Parse error: parse error, expecting PHP For Loop 解析错误:语法错误,意外的'{',需要'('帮助? - Parse error: syntax error, unexpected '{', expecting '(' help? 解析错误:语法错误,意外'(',期待','或';'in - Parse error: syntax error, unexpected '(', expecting ',' or ';' in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM