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
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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.