dtt27783 2017-09-30 18:02
浏览 82
已采纳

解析错误:语法错误,第9行代码中的意外'(',期望变量(T_VARIABLE)或'$'[重复]

This question already has an answer here:

<?php

$name          = $_POST['name'];
$price         = $_POST['price'];
$absolute_path = "/Plants/List/index.html";

$PlantFile = fopen($_SERVER['DOCUMENT_ROOT'] . "$absolute_path", "a") or die("Unable to open file!");
$trimmedname = preg_replace('/\s+/', '', $name);
fwrite($PlantFile, "

<div class='wrapper one $trimmedname' id='main'>
<h1>$name</h1>
<p>Price: $price</p>
 <?php if($_SESSION[id]) {?> 
<button>Delete $name</button>
<script> var simple = \"<?php echo $trimmedname; ?>\"; $(\"button\").click(function(){$(simple).remove();}); </script> 
 <?php } ?> 
</div>
");

fclose($PlantFile);


?>

I keep getting the error:

Parse error: syntax error, unexpected '(', expecting variable (T_VARIABLE) or '$' in your code on line 9

Could anyone help? Thanks guys!

</div>
  • 写回答

1条回答 默认 最新

  • douyan1903 2017-09-30 18:18
    关注

    I think the problem lies in your use of the curly braces in combination with the $ sign aka {$(simple).remove();}.

    try replacing $ with \$ so that your jQuery $ sign wont be treated as a php variable.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站