Jump to content

Show Form Results On Same Page


BryanVest

Recommended Posts

I know the php is basic and not completed yet, but I am working on that. My next step I want the result to show on index.php when a form is submitted to calculator2.php. I just cant seem to get it. Please help!

 

index.php

<div class="post">
        <h2 class="title">Calculator</h2>
	<hr />
         <form method="post" action="calculator2.php">
Fireplace Front Width: <input type="text" name="fw">
<br />
Fireplace Back Width: <input type="text" name="bw">
<br />
Fireplace Depth: <input type="text" name="fd">
<br />
<input type="submit" name="Submit" value="Submit">
		</form>
            Pounds Of Glass Needed: <?php echo $res1; ?>

      </div>

 

 

calculator2.php

<?php
$frontwidth = $_POST['fw'];
$backwidth = $_POST['bw'];
$firedepth = $_POST['fd'];
$x = $frontwidth + $backwidth+ $firedepth;
$y = ($x / 3) * .6667; 
$res1 = $y *2;
echo $res1;
?>

Link to comment
https://forums.phpfreaks.com/topic/246596-show-form-results-on-same-page/
Share on other sites

<?php	

if(isset($_POST['Submit']))
{
	$frontwidth = $_POST['fw'];	
	$backwidth = $_POST['bw'];	
	$firedepth = $_POST['fd'];	
	$x = $frontwidth + $backwidth+ $firedepth;	
	$y = ($x / 3) * .6667; 	
	$res1 = $y *2;	
	echo $res1;
	echo $frontwidth;
}
?>
<div class="post">        
<h2 class="title">Calculator</h2>		
<hr />         
<form method="post" action="index.php">
Fireplace Front Width: 
<input type="text" name="fw">
<br />
Fireplace Back Width: 
<input type="text" name="bw">
<br />Fireplace Depth: 
<input type="text" name="fd">
<br />
<input type="submit" name="Submit" value="Submit">			
</form>            
Pounds Of Glass Needed: <?php echo $res1; ?>				      
</div>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.