zend Posted June 19, 2008 Share Posted June 19, 2008 im new to php and im simply trying to create a converter from Fahrenheit to Celsius and back. I have tried everything and i dont know why whenever it converts it comes up with 32 for Fahrenheit(obviously its coming up with 0 * 32 for some reason) and for Celsius im just getting way wrong numbers. plzzz any help would be greatly appreciated <HTML> <BODY> <form action="m2.php" method"get"> <input type="text" name"degrees" /> <input type="radio" name="CorF" value="a" /> °C <input type="radio" name="CorF" value="b" /> °F <input type="submit" /> </form> <?php $degrees = $_GET["degrees"]; $temp = $_GET["CorF"]; $fahrenheit = (($degrees * 1. + 32); $celsius = (($degrees - 32) / 1.; if ($temp == "a") echo "The temperature in Fahrenheit is ", $fahrenheit; if ($temp == "b") echo "The temperature in Celsius is ", $celsius; ?> </BODY> Link to comment https://forums.phpfreaks.com/topic/110968-new-to-php-need-help-with-code/ Share on other sites More sharing options...
zend Posted June 19, 2008 Author Share Posted June 19, 2008 lol btw the smiley faces are eights. Link to comment https://forums.phpfreaks.com/topic/110968-new-to-php-need-help-with-code/#findComment-569295 Share on other sites More sharing options...
kenrbnsn Posted June 19, 2008 Share Posted June 19, 2008 That's why you would put your code between tags in this forum... Ken Link to comment https://forums.phpfreaks.com/topic/110968-new-to-php-need-help-with-code/#findComment-569300 Share on other sites More sharing options...
kenrbnsn Posted June 19, 2008 Share Posted June 19, 2008 You shouldn't be doing the processing until after the form is submitted: <?php if (isset($_GET['submit'])) { $degrees = $_GET["degrees"]; $temp = $_GET["CorF"]; $fahrenheit = (($degrees * 1.8 + 32); $celsius = (($degrees - 32) / 1.8; if ($temp == "a") echo "The temperature in Fahrenheit is ", $fahrenheit; if ($temp == "b") echo "The temperature in Celsius is ", $celsius; } ?> <HTML> <BODY> <form action="m2.php" method"get"> <input type="text" name"degrees" /> <input type="radio" name="CorF" value="a" /> °C <input type="radio" name="CorF" value="b" /> °F <input type="submit" name="submit" /> </form> </BODY> </html> Ken Link to comment https://forums.phpfreaks.com/topic/110968-new-to-php-need-help-with-code/#findComment-569303 Share on other sites More sharing options...
Ironphp Posted June 19, 2008 Share Posted June 19, 2008 In addition to what Ken said, the reason your form is not working is that because the form is not properly submitting the GET variable of degrees. <input type="text" name"degrees" /> change that to <input type="text" name="degrees" /> You (are) were missing an equals sign. Thus, since $_GET[degrees] was always zero, that will explain why oF was always 32. Regards, Ironphp Link to comment https://forums.phpfreaks.com/topic/110968-new-to-php-need-help-with-code/#findComment-569312 Share on other sites More sharing options...
zend Posted June 22, 2008 Author Share Posted June 22, 2008 o wow how did i miss that, had like 2 other people look at it too. thanks alot always helps to get a 2nd pair of eyes on some code. Link to comment https://forums.phpfreaks.com/topic/110968-new-to-php-need-help-with-code/#findComment-571643 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.