1

I used a PHP code plugin called insert PHP in wordpress page. I have written a code which shows me a syntax error when run, what should I do?:

The error it gives is

Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\mapletreefarm\wp-content\plugins\insert-php\insert_php.php(48) : eval()'d code on line 9"

[insert_php]
if(isset($_POST["submit"])){
echo $_POST["name"];
echo "<br>";
echo $_POST["email"];
}
else 
{  
[/insert_php] 

<html>
<body>
<form action=" " method="post">
Name: <input type="text" name="name"> <br>
E-mail: <input type="text" name="email"> <br>
<input type="submit" name="submit">
</form>

</body>
</html>  
[insert_php]
}
[/insert_php]  
Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

1

The reason you are getting this error is because the php_insert plugin parses each php block as a stand-alone block of code.
So, your first block is a block of code that ends in {, which is impossible.

The only way I see to make this work is to put all code in a single php block and echo the html for the form.

[insert_php]
if (isset($_POST["submit"])) {
    echo $_POST["name"];
    echo "<br>";
    echo $_POST["email"];
}
else 
{

    echo '<html>
        <body>
            <form method="post">
                Name: <input type="text" name="name"><br />
                E-mail: <input type="text" name="email"><br />
                <input type="submit" name="submit">
            </form>
        </body>
    </html>';
}
[/insert_php]
Jerodev
  • 32,252
  • 11
  • 87
  • 108