开发者

PHP Echo Fails in Quotes

Here's the code:

<form method="POST" action="<? echo $PHP_SELF; ?>" enctype="multipart/form-data">

It displays as HTML:<form method="POST" action="<? echo $PHP_SELF; ?>" enctype="multipart/form-data">

PHP works on th开发者_StackOverflow社区e rest of my code but this one has me itching my head

EDIT:

Here is the code to display it:

<?
$AssignedTo = $_POST['id'];
if (isset ($_POST['submit'])) // if the form was submitted, display their name
{
// Action to be completed once the form is submitted
}
else // form hasn't been submitted, so display the form
{
echo '<form method="POST" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
<h2>**** - Add </h2>
</form>';
}
?>


Since you're already echoing the string wrapping it in another PHP block is unnecessary and won't be parsed

<?
$AssignedTo = $_POST['id'];
if (isset ($_POST['submit'])) // if the form was submitted, display their name
{
// Action to be completed once the form is submitted
}
else // form hasn't been submitted, so display the form
{
echo '<form method="POST" action="'.$PHP_SELF.'" enctype="multipart/form-data">
<h2>**** - Add </h2>
</form>';
}
?>

That should work.


Should it not be <?php rather than <? ?

What happens if you use

<? echo "action='".$PHP_SELF."'"; ?>

(So you wrap the action inside the echo)?

Using single quotes ' ' makes the PHP complier treat the whole thing as a literal string, so it will never echo the variable referenced by $PHP_SELF, but the actual string "$PHP_SELF"

(Also you've got nested PHP Tags? That makes no sense)

echo '<form method="POST" action="'.$PHP_SELF.'" enctype="multipart/form-data">
<h2>**** - Add </h2>
</form>';

Alternative Method:

printf('<form method="POST" action="%s" enctype="multipart/form-data">
<h2>**** - Add </h2>
</form>', $PHP_SELF);


Are you sure short tags are allowed to execute php?


Does <?php .... ?> work?

The <? syntax is configurable: http://www.php.net/manual/en/language.basic-syntax.phpmode.php


Don't embed PHP open tags within PHP itself

echo '<form method="POST" action="',$PHP_SELF,'" enctype="multipart/form-data">


First use <?php also check for opened quotes in the previous code. If you post the rest of the code would be easier.

Nested PHP tags very wrong:

<?php
$AssignedTo = $_POST['id'];
if (isset ($_POST['submit'])) // if the form was submitted, display their name
{
// Action to be completed once the form is submitted
}
else // form hasn't been submitted, so display the form
{
echo '<form method="POST" action="'.echo $PHP_SELF.'" enctype="multipart/form-data">
<h2>**** - Add </h2>
</form>';
}
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜