Get Result in html

Dear sir my html file has following coedes

[code]<Html>
<head>
<title>Add two numbers on same form</title>
<body>
<center>
<h1><font color="blue"> Sum Two Numbers</font></h1>
<form name="thisform" method="Get" action="getsum2.php">
<table cellpadding=3 cellspacing=3>
<tr>
<td>Enter First Number</td><td><input type="Text" name="text1"></td>
</tr>

<tr>
<td>Enter Second Number</td><td><input type="Text" name="text2"></td>
</tr>
<tr>
<td style="color: #ff0000">Result</td><td><input type="Text" name="text2" disabled></td>
</tr>

<tr>
<td colspan=2 align="center"><input type="Submit" Value="Result"></td>
</tr>
</table>
</center>
</body>
</html>[/code]

And getsum2.PHP file has these codes

<?php $num1=$_GET['text1']; $num2=$_GET['text2']; $result=$num1+$num2; echo "Result= $result"; ?>

These both file works fine. The result is show in getsum2 php.
But I want to get result in sum2.html’s text3.

Both files are in attachment.

Please help
Please help


New folder.zip (735 Bytes)

you should merge the files

have one php file where you first do your logic and then do your html afterwards. change the form to submit to itself (just remove the action attribute)

then in the view part check if the result is set, and if so echo it into the field where you want it

Here’s how to do it in one file :wink:

file name: getting_result.php
[php]<?php
if (isset($_POST[‘submitBtn’]) && $_POST[‘submitBtn’] == ‘Result’) {
$foo = $_POST[‘foo’];
$bar = $_POST[‘bar’];
$fooBar = $foo + $bar;
}
?>

Getting a Result

Sum Two Numbers

Enter First Number
Enter Second Number
Result
[/php]

P.S. I like using $_POST for I read many good tutorials stating to use $_POST when you can over $_GET

Thanks Sir,

Your code work fine but I want to know more about this line of code
[php] [/php]

Specially want to what is meaning of these codes

[php]"<?php echo isset($foo) ? $foo : 0; ?>"[/php]

Please help again

Sponsor our Newsletter | Privacy Policy | Terms of Service