在html中输出的PHP

问题描述:

我正在尝试在同一页面的文本框中发布php的结果,但不知道如何做。代码如下在html中输出的PHP

<form action = "<?php $_PHP_SELF ?>" method = "GET" > 
     Input1: <input type = "text" name = "input1" /> 
     Input2: <input type = "text" name = "input2" /> 
     Result: <input type = "text" name = "result" /> 

     <input type = "submit" /> 


    </form> 

完整代码:

<?php 
$input1 = $_GET["input1"]; 
$input2 = $_GET["input2"]; 
$result = $input1 + $input2; 
echo "$result"; 
?> 
<html> 
<body> 
<form action = "<?php $_PHP_SELF ?>" method = "GET" > 
    Input1: <input type = "text" name = "input1" /> 
    Input2: <input type = "text" name = "input2" /> 
    Result: <input type = "text" name = "result" /> 
    <input type = "submit" /> 
</form> 
</body> 
</html> 

我想表明的结果的文本框$结果。 谢谢。

+1

的哪里是'$ result'设置? – mulquin

+1

php有什么结果? – ThisGuyHasTwoThumbs

+0

Complete Code:

\t \t ” 方法= “GET”> \t \t \t输入1: \t \t \t输入2: \t \t \t结果: \t \t \t \t \t \t \t \t \t \t \t \t \t \t –

您可以通过设置value

<?php 

$input1 = $_GET["input1"]; 
$input2 = $_GET["input2"]; 
$result = $input1 + $input2; 
echo "$result"; 
?> 
<html> 
    <body> 
     <form action = "<?php $_PHP_SELF ?>" method = "GET" > 
      Input1: <input type = "text" name = "input1" value="<?=$input1?>" /> 
      Input2: <input type = "text" name = "input2" value="<?=$input2?>"/> 
      Result: <input type = "text" name = "result" value="<?=$result?>"/> 
      <input type = "submit" /> 
     </form> 
    </body> 
</html> 
+0

谢谢B.Desai。它为我工作。 –

+1

@MudassirHussain如果它的工作,标记为接受:) – ThisGuyHasTwoThumbs

做我假设某种加入这里

<form action = "<?php $_PHP_SELF ?>" method = "POST" > 
     Input1: <input type = "text" value="<?php echo $_POST['input1']; ?>" name = "input1" /> 
     Input2: <input type = "text" value="<?php echo $_POST['input2']; ?>" name = "input2" /> 
     Result: <input type = "text" value="<?php echo ($_POST['input1']+ $_POST['input2']); ?>" name = "result" /> 

     <input type = "submit" /> 


    </form>