PHP Echo在行情中失败

时间:2010-11-17 15:50:59

标签: php forms post echo

以下是代码:

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

显示为HTML:<form method="POST" action="<? echo $PHP_SELF; ?>" enctype="multipart/form-data">

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="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
<h2>**** - Add </h2>
</form>';
}
?>

6 个答案:

答案 0 :(得分:2)

因为你已经在回复字符串包装它在另一个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="'.$PHP_SELF.'" enctype="multipart/form-data">
<h2>**** - Add </h2>
</form>';
}
?>

这应该有效。

答案 1 :(得分:1)

是不是<?php而不是<?

如果您使用

会发生什么

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

(所以你将动作包裹在回声中)?

使用单引号''使PHP编译器将整个事物视为文字字符串,因此它永远不会回显$ PHP_SELF引用的变量,而是实际的字符串“$ PHP_SELF”

(你还有嵌套的PHP标签吗?没有意义)

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

替代方法:

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

答案 2 :(得分:0)

首次使用<?php也检查上一代码中已打开的引号。如果您发布其余代码会更容易。

嵌套的PHP标记非常错误:

<?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>';
}
?>

答案 3 :(得分:0)

你确定允许短标签执行php吗?

答案 4 :(得分:0)

&lt; ?php .... ?>是否有效?

<?语法是可配置的:http://www.php.net/manual/en/language.basic-syntax.phpmode.php

答案 5 :(得分:0)

不要在PHP本身中嵌入PHP开放标记

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