HELP WITH PROGRAM!

Hi there, I’m working on a HTML and PHP program, which converters temperatures, the HTML file has a form which gets the calculations from a PHP form and then shows the results. The program I am getting is that it doesn’t show the result on the html page, it just comes up blank. Please help! Thank you!!
The html file is called “index.html” and the php form is called “convert.php”

Below is the final product I have come up with

[php]

Unit Converter

CONVERSION

Type of conversion:
Select type... --Temperature-- Celsius to Fahrenheit Celsius to Kelvin Celsius to Rankine Kelvin to Celsius Kelvin to Fahrenheit Kelvin to Rankine Fahrenheit to Celsius Fahrenheit to Kelvin Fahrenheit to Rankine Rankine to Celsius Rankine to Kelvin Rankine to Fahrenheit

Value to convert:


[/php] -------------------------------------------------- [php] Conversion Output <?php $conversionType = $_POST['conversionType']; $conversionInput = $_POST['conversionInput']; $conversionValue; $conversionFrom; $conversionTo; if ($conversionType == 'C-F') { $conversionValue = $conversionInput * (5/9) + 32; $conversionFrom = "° Celsius"; $conversionTo = "° Fahrenheit"; } if ($conversionType == 'C-K') { $conversionValue = $conversionInput + 273.15; $conversionFrom = "° Celsius"; $conversionTo = "° Kelvin"; } if ($conversionType == 'C-R') { $conversionValue = ($conversionInput + 273.15) * (9/5); $conversionFrom = "° Celsius"; $conversionTo = "° Rankine"; } if ($conversionType == 'K-C') { $conversionValue = $conversionInput - 273.15; $conversionFrom = "° Kelvin"; $conversionTo = "° Celsius"; } if ($conversionType == 'K-F') { $conversionValue = $conversionInput * (9/5) - 459.67 ; $conversionFrom = "° Kelvin"; $conversionTo = "° Fahrenheit"; } if ($conversionType == 'K-R') { $conversionValue = $conversionInput * (9/5); $conversionFrom = "° Kelvin"; $conversionTo = "° Rankine"; } if ($conversionType == 'F-C') { $conversionValue = ($conversionInput - 32) * (5/9) ; $conversionFrom = "° Fahrenheit"; $conversionTo = "° Celsius"; } if ($conversionType == 'F-K') { $conversionValue = ($conversionInput + 459.67) * (5/9); $conversionFrom = "° Fahrenheit"; $conversionTo = "° Kelvin"; } if ($conversionType == 'F-R') { $conversionValue = $conversionInput + 459.67; $conversionFrom = "° Fahrenheit"; $conversionTo = "° Rankine"; } if ($conversionType == 'R-C') { $conversionValue = ($conversionInput + 491.67) * (5/9); $conversionFrom = "° Rankine"; $conversionTo = "° Celsius"; } if ($conversionType == 'R-K') { $conversionValue = $conversionInput * (5/9); $conversionFrom = "° Rankine"; $conversionTo = "° Kelvin"; } if ($conversionType == 'R-F') { $conversionValue = $conversionInput - 459.67; $conversionFrom = "° Rankine"; $conversionTo = "° Fahrenheit"; } echo "$conversionInput $conversionFrom = $conversionValue $conversionTo"; ?>[/php]

HTH :wink:
[php]<?php
/* Check out http://php.net/manual/en/function.filter-input.php */
$conversionType = filter_input(INPUT_POST, ‘conversionType’, FILTER_SANITIZE_SPECIAL_CHARS);
$conversionInput = filter_input(INPUT_POST, ‘conversionInput’, FILTER_SANITIZE_SPECIAL_CHARS);

/* The if statement forces the code from running until the user has submitted input /
if ( filter_input(INPUT_POST, ‘submit’, FILTER_SANITIZE_SPECIAL_CHARS) && $conversionType && $conversionInput ) {
/
I would check into using a switch statement - http://php.net/manual/en/control-structures.switch.php */
if ($conversionType == ‘C-F’)
{
$conversionValue = $conversionInput * (5/9) + 32;
$conversionFrom = “&#176; Celsius”;
$conversionTo = “&#176; Fahrenheit”;
}
if ($conversionType == ‘C-K’)
{
$conversionValue = $conversionInput + 273.15;
$conversionFrom = “&#176; Celsius”;
$conversionTo = “&#176; Kelvin”;
}
if ($conversionType == ‘C-R’)
{
$conversionValue = ($conversionInput + 273.15) * (9/5);
$conversionFrom = “&#176; Celsius”;
$conversionTo = “&#176; Rankine”;
}
if ($conversionType == ‘K-C’)
{
$conversionValue = $conversionInput - 273.15;
$conversionFrom = “&#176; Kelvin”;
$conversionTo = “&#176; Celsius”;
}
if ($conversionType == ‘K-F’)
{
$conversionValue = $conversionInput * (9/5) - 459.67 ;
$conversionFrom = “&#176; Kelvin”;
$conversionTo = “&#176; Fahrenheit”;
}
if ($conversionType == ‘K-R’)
{
$conversionValue = $conversionInput * (9/5);
$conversionFrom = “&#176; Kelvin”;
$conversionTo = “&#176; Rankine”;
}
if ($conversionType == ‘F-C’)
{
$conversionValue = ($conversionInput - 32) * (5/9) ;
$conversionFrom = “&#176; Fahrenheit”;
$conversionTo = “&#176; Celsius”;
}
if ($conversionType == ‘F-K’)
{
$conversionValue = ($conversionInput + 459.67) * (5/9);
$conversionFrom = “&#176; Fahrenheit”;
$conversionTo = “&#176; Kelvin”;
}
if ($conversionType == ‘F-R’)
{
$conversionValue = $conversionInput + 459.67;
$conversionFrom = “&#176; Fahrenheit”;
$conversionTo = “&#176; Rankine”;
}
if ($conversionType == ‘R-C’)
{
$conversionValue = ($conversionInput + 491.67) * (5/9);
$conversionFrom = “&#176; Rankine”;
$conversionTo = “&#176; Celsius”;
}
if ($conversionType == ‘R-K’)
{
$conversionValue = $conversionInput * (5/9);
$conversionFrom = “&#176; Rankine”;
$conversionTo = “&#176; Kelvin”;
}
if ($conversionType == ‘R-F’)
{
$conversionValue = $conversionInput - 459.67;
$conversionFrom = “&#176; Rankine”;
$conversionTo = “&#176; Fahrenheit”;
}
$output = $conversionInput . htmlspecialchars_decode($conversionFrom) . " = " . $conversionValue . htmlspecialchars_decode($conversionTo);
}
?>

Conversion Program

CONVERSION

<?php echo isset($output) ? $output : NULL; ?>

Type of conversion:
Select type... --Temperature-- Celsius to Fahrenheit Celsius to Kelvin Celsius to Rankine Kelvin to Celsius Kelvin to Fahrenheit Kelvin to Rankine Fahrenheit to Celsius Fahrenheit to Kelvin Fahrenheit to Rankine Rankine to Celsius Rankine to Kelvin Rankine to Fahrenheit

Value to convert:


[/php]

I personally think this can be done in one file, I called it converstionTable_ver01.php.

I can be done in a single file. One notable issue,

[php]

Conversion Output [/php]

??? See anything wrong with what is at the top of your PHP script?

Sponsor our Newsletter | Privacy Policy | Terms of Service