Jump to content

Making a page post back to itself


mikevarela

Recommended Posts

Making a calculator and would like the submit button to calculate and post back the answer to the same page. In the below example I get the answer on a cleared out page. I kinda want to do this AJAX style but use PHP.. is there any way to handle this?

 

<?php



$sampleRate 	=	$_POST['sample_rate']; 
$bitDepth		=	$_POST['bit_depth'];
$channels		=	$_POST['channels'];
$timeSeconds	=	$_POST['time_minutes'] * 60;

// Sample Rate X Bit Depth
$sampleBit = $sampleRate * $bitDepth;

// multiply number of channels
$sampleBitWithChannels = $sampleBit * $channels;

// Convert To Bytess
$bytes = $sampleBitWithChannels / 8; 

// Add Seconds
$bytesSeconds = $timeSeconds * $bytes;

// get MB figure
$MB	= ($bytesSeconds / 1024) / 1024;


if(! $_POST['calculate']) {


?>

<html>
<head>
<title>Calculate File Size</title>
</head>

<body>



<form method="post" action="">
<fieldset>
<legend>File Size Calculation</legend>

<table>	
<tr>
	<td>
		Sample Rate
	</td>
	<td>
		<select name="sample_rate" id="sample_rate">
			<option>32000</option>
			<option>44100</option>
			<option>48000</option>
			<option>88100</option>
			<option>96000</option>
			<option>192000</option>
		</select>
	</td>
</tr>
<tr>
	<td>
		Bit Depth
	</td>
	<td>
		<select name="bit_depth" id="bit_depth">
			<option>8</option>
			<option>12</option>
			<option>16</option>
			<option>24</option>
		</select>
	</td>
</tr>
<tr>
	<td>
		Channels
	</td>
	<td>
		<select name="channels" id="channels">
			<option>1</option>
			<option>2</option>
			<option>3</option>
			<option>4</option>
			<option>5</option>
			<option>6</option>
			<option>7</option>
			<option>8</option>
		</select>
	</td>
</tr>
<tr>
	<td>
		Time in Minutes
	</td>
	<td>
		<input type="text" name="time_minutes" id="time_minutes" size="5" />
	</td>
</tr>
<tr>
	<td>
		<input type="submit" name="calculate" id="calculate" value="calculate" />
		<input type="reset" value="reset" />
	</td>
</tr>
</table>
</fieldset>
</form>

<h3>Common Standards</h3>
<table border="1">
<tr>
<td>Compact Disc</td>
<td>Movie</td>
<tr>
<tr>
<td>44.1kHz / 16bit</td>
<td>48kHz / 24bit</td>
</tr>


</table>






</body>
</html>

<?php
}
else
{	
	echo '<p>Your Value is: ' . round($MB) . ' MB</p>';
}
?>


Link to comment
https://forums.phpfreaks.com/topic/187724-making-a-page-post-back-to-itself/
Share on other sites

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.