A_Brave_Panda A_Brave_Panda - 3 years ago 292
Javascript Question

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

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

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!

Aki Aki
Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download