I'm trying to encode a simple code but I'm getting this error:
Parse error: syntax error, unexpected '<' in C:\wamp\www\test.php(2) : eval()'d code on line 1
This is the code:
<form method="POST" action="">
Enter your command: <input type='text' name='cmd'> <input type='submit' name='execute' value='Execute'>
</form>
echo $_POST['cmd'];
This is the base64_encode with eval:
<?
eval(base64_decode('PGZvcm0gbWV0aG9kPSJQT1NUIiBhY3Rpb249IiI+CkVudGVyIHlvdXIgY29tbWFuZDogPGlu cHV0IHR5cGU9J3RleHQnIG5hbWU9J2NtZCc+IDxpbnB1dCB0eXBlPSdzdWJtaXQnIG5hbWU9J2V4ZWN1dGUnIHZhbHVl PSdFeGVjdXRlJz4KPC9mb3JtPgoKCmVjaG8gJF9QT1NUWydjbWQnXTsK'));
?>
That is because you are trying to eval non-php code (html form)
You forgot the PHP tags around your code:
<?php
// Any PHP code as needed
?>
<form method="POST" action="">
Enter your command: <input type='text' name='cmd'> <input type='submit' name='execute' value='Execute'>
</form>
<?php
echo $_POST['cmd'];
?>
Related
I want to insert $_POST value into the HTML form action. By using my code I got this error message: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) ....
This is my sample code in my PHP file:
print <<< HERE
<form action="../../path/to/file.php?id=<?php echo $_POST['mytext'];?>" method="POST">
// some stuff here ...
<input type="text" name="mytext" id="mytext" value="">
<input type="submit" value="Submit">
</form>
HERE;
What is wrong with my code?
You don't need to add id in the form action
<form action="../../path/to/file.php" method="POST">
// some stuff here ...
<input type="text" name="mytext" id="mytext" value="">
<input type="submit" value="Submit">
</form>
Instead in the file.php you can make a variable and assign $_POST['mytext'] to that variable
$id = $_POST['mytext'];
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
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]
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]
I am trying to pass a certain data which I found in my table using the search to another php page . here is my code
echo "
1<form action="adm_edit.php?product_code=$record[0]" method="POST">
2<input type=submit value=Edit>
3</form>
4<form action="adm_edit.php?product_code=$record[0]" method="POST">
5<input type=submit value=Delete>
6</form>
";
my search function is working fine and record[0] is contain desired data but I am getting this error when I run this code:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in search.php on line 1
I put numbers on lines in above code for ease of reading
So could you please help me?
Thank you
Take care when using quotes from html elements in echos, also when using variables!
When using ' instead of ", you also have to put quotes in front of the variable and that way you stop echoing a string and can start with echoing a variable. You need to concatenate the var and the string with a . !
This will work :
echo '
<form action="adm_edit.php?product_code='.$record[0].'" method="POST">
<input type=submit value=Edit>
</form>
<form action="adm_edit.php?product_code='.$record[0].'" method="POST">
<input type=submit value=Delete>
</form>
';
<form action="adm_edit.php?product_code=<?php echo $record[0]; ?>" method="POST">
<input type=submit value=Edit>
</form>
<form action="adm_edit.php?product_code=<?php echo $record[0]; ?>" method="POST">
<input type=submit value=Delete>
</form>
I'm trying to learn PHP using NetBeans although I've come up against a problem with the interpreter and I can't tell how to fix it.
It's to do with the notation <<<_END. It should, from what I'm learning wrap everything into a variable until it's ended with _END
However, if I plug in the following example:
<?php
echo <<<_END
<html><head><title>PHP form upload</title></head><body><form method='post' action='upload.php' enctype='multipart/form-data'>
Select File: <input type='file' name='filename' size='10' />
<input type='submit' value='Upload'/>
</form>
_END
if ($_FILES)
{
$name = $_FILES ['filename']['name'];
move_uploaded_file($_FILES ['filename'][tmp_none], $name);
echo "Uploaded image '$name' <br/> <img src='$name'/>";
}
echo "</body></html>";
?>
I get the following error message
Parse error: syntax error, unexpected T_SL in script.php on line 13, where line 13 is the code that says 'echo <<<_END'.
Can anyone help me, please?
There must be no space/tab/indentation before ending _END like this:
echo <<<_END
<html><head><title>PHP form upload</title></head><body><form method='post' action='upload.php' enctype='multipart/form-data'>
Select File: <input type='file' name='filename' size='10' />
<input type='submit' value='Upload'/>
</form>
_END;
Don't forget that it is not allowed to
indent the closing tag if you do so
you will get a parsing error.
http://www.phpf1.com/tutorial/php-heredoc-syntax.html
Missing semicolon after _END
You can't have any indentation before _END
Trying to print out some html forms but I get a parsing syntax error. I believe it gets stuck on the SERVER[PHP_SELF] but I'm not sure. How can I get this to echo correctly?
Error occurs on the SERVER[PHP_SELF] line
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING
function drawbuttons()
{
echo <<<EOT
<table>
<tr><td>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<input type="submit" name="previous" value="Previous" STYLE="font-size:12pt; background-color:00BFFF; color:ffffff">";
</form>
</td>
<td>
<form action="<?=$_SERVER['PHP_SELF'];?>" method="post">
<input type="submit" name="next" value="Next"STYLE="font-size:12pt; background-color:00BFFF; color:ffffff">
</form>
</td></tr>
</table>
EOT;
}
From the manual on the heredoc syntax:
Heredoc text behaves just like a double-quoted string, without the double quotes. This means that quotes in a heredoc do not need to be escaped, but the escape codes listed above can still be used. Variables are expanded, but the same care must be taken when expressing complex variables inside a heredoc as with strings.
That means you can’t use PHP open or close tags and you need to use the proper syntax for variables. In this case use the curly brace syntax:
echo <<<EOT
<table>
<tr><td>
<form action="{$_SERVER['PHP_SELF']}" method="post">
<input type="submit" name="previous" value="Previous" STYLE="font-size:12pt; background-color:00BFFF; color:ffffff">";
</form>
</td>
<td>
<form action="{$_SERVER['PHP_SELF']}" method="post">
<input type="submit" name="next" value="Next"STYLE="font-size:12pt; background-color:00BFFF; color:ffffff">
</form>
</td></tr>
</table>
EOT;
You can't use PHP opening tags (short or not) inside heredocs.
Use instead:
<form action="{$_SERVER['PHP_SELF']}" method="post">