zobi316 Posted November 6, 2008 Share Posted November 6, 2008 im trying to creat a script in php that will allow me to convert between imperial and Metric. i have been asked to use the following values for the purposes of conversion: 1 mile = 1.609 kilometres 1 inch = 2.54 centimetres 1 pound = 0.454 kilograms 1 horsepower = 0.746 kilowatts 1 pint = 0.568 I have dones the conversion from imperial to metric e.g 1 mile is 1.609 kilometres, but stuck on how i will convert from kilometres to miles. so that when u click submit, it should display 1.609 kilometres = 1 mile. I think i've done the coding correct for this is well but not sure: <?php $number1 =$_POST[number1]; $converter =$_POST[converter]; if($converter == "Kilometres"){ $answer = $number1 / 1.609; $unit = "Mile"; } if($converter =="centimetres"){ $answer = $number1 / 2.54; $unit = "inch"; } if($converter == "kilograms"){ $answer = $number1 / 0.454; $unit = "pound"; } if($converter == "kilowatts"){ $answer = $number1 / 0.746; &unit = "horsepower"; } if($converter == "litres"){ $answer = $number1 / 0.568; &unit = "pint"; } ?> How do i get it working, will it need to go in another page. If so how, its not working. Here is the code: <html> <head> <title>Converter</title> </head> </body> <form name="form1" method="post" action="conversion1.php"> <input name="number1" type="text" id="number1"> <select name="converter" id="converter"> <option value="Miles" selected>Miles</option> <option value="Inch">Inch</option> <option value="Pound">Pound</option> <option value="Horsepower">Horsepower</option> <option value="Pint">Pint</option> </select> <input name="submit" type="submit" id="submit" value="="> </form> </body> </html> <?php $number1 =$_POST[number1]; $converter =$_POST[converter]; if($converter == "Miles"){ $answer = $number1 * 1.609; $unit = "Kilometres"; } elseif($converter =="Inch"){ $answer = $number1 * 2.54; $unit = "Centimetres"; } elseif($converter =="Pound"){ $answer = $number1 * 0.454; $unit = "Kilograms"; } elseif($converter =="Horsepower"){ $answer = $number1 * 0.746; $unit = "Kilowatts"; } elseif($converter =="Pint"){ $answer = $number1 * 0.568; $unit = "litres"; } echo "$answer $unit"; ?> Why won't my second part of code function, so that when i click submit it should display 1.609 kilometeres = 1 mile. In the end, i should have 2 submit buttons. Please help (edited by kenrbnsn to add tags) Link to comment https://forums.phpfreaks.com/topic/131672-conversion/ Share on other sites More sharing options...
Alt_F4 Posted November 7, 2008 Share Posted November 7, 2008 do you have another form that you are using to convert from kilometers to miles or are you using the one below?? <html> <head> <title>Converter</title> </head> </body> <form name="form1" method="post" action="conversion1.php"> <input name="number1" type="text" id="number1"> <select name="converter" id="converter"> <option value="Miles" selected>Miles</option> <option value="Inch">Inch</option> <option value="Pound">Pound</option> <option value="Horsepower">Horsepower</option> <option value="Pint">Pint</option> </select> <input name="submit" type="submit" id="submit" value="="> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/131672-conversion/#findComment-684358 Share on other sites More sharing options...
zobi316 Posted November 7, 2008 Author Share Posted November 7, 2008 Im using another one. I just changed the wording in the code. Is that probably why. I'm kinda confused, Please help Link to comment https://forums.phpfreaks.com/topic/131672-conversion/#findComment-684888 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.