forms - Temperature Conversion PHP -
forms - Temperature Conversion PHP -
i have been working on next simple temperature conversion using html , php. first effort @ using php , can't seem right.
i sure there lots of errors in code please patient!
here have:
<!doctype html> <html> <head> <title>temp conversion</title> <meta charset="utf-8"> <body> <form name="tempconvert" method="post" action="<?php echo $_server["php_self"]; ?>"> <table> <tr> <td>enter value convert</td> <td><input type="text" name="valueconvert" id="valueconvert" size="15"></td> </tr> <tr> <td>convert to:</td> <td><select name="converttype" id="converttype" size="1"> <option disabled> select measurement type</option> <option value="celsius">celsius</option> <option value="fahrenheit">fahrenheit</option> </select> </td> </tr> <tr> <td><input type="submit" name="btnconvert" id="btnconvert" value="convert"></td> <td><input type="reset" name="btnreset" id="btnreset" value="reset"></td> </tr> </form> <?php $valueconvert = $_post['valueconvert']; $converttype = $_post['converttype']; function tempconvert($valueconvert, $converttype){ if($converttype == "fahrenheit"){ $conversion = ((9/5)*$valueconvert) +(32); } else if ($converttype == "celsius"){ $conversion = ($valueconvert - 32) * (9/5); } homecoming $conversion; echo "the initial temperature $valueconvert. new temperature $conversion."; } ?> </body> </html>
i can't figure out how pass users textbox input , dropdown list selection php function.
you pretty much have things set alright. not calling function though.
you echo statement comes after homecoming statement , never executed.
it improve this:
<?php function tempconvert($valueconvert, $converttype) { if($converttype == "fahrenheit"){ $conversion = ((9/5) * $valueconvert) + (32); } else if ($converttype == "celsius"){ $conversion = ($valueconvert - 32) * (5/9); } homecoming $conversion; } $valueconvert = $_post['valueconvert']; $converttype = $_post['converttype']; $conversion = tempconvert($valueconvert, $converttype); echo "the initial temperature $valueconvert. new temperature $conversion."; ?>
php forms post
Comments
Post a Comment