I am a beginner to PHP and I thought it would be nice to learn it by starting simple projects. I chose to start with a simple unit converter.
I do not want to ask for a code, I simply would like to ask for some help with figuring out what methods to use or what steps should I consider next. Or if someone has a link to something similar it would be great, I couldn't find anything myself.
The idea is this: the user will input the value and the original unit, and then I want to print the value in a few different units. This is what I have so far:
html
<div id="converter">
<h2>Unit converter</h2>
Convert from:
<form method="post" action="" class="inline">
<select name="unit">
<option value="km">kilometers</option>
<option value="m">meters</option>
<option value="dm">decimeters</option>
<option value="cm">centimeters</option>
<option value="mm">milimeters</option>
</select>
<input type="text" name="value" placeholder="input value here" autocomplete="off" required>
<input type="submit" value="convert"/>
</form>
<?php
$unit = isset($_POST['unit']) ? $_POST['unit'] : false;
$value = isset($_POST['value']) ? $_POST['value'] : false;
/* the above two lines are copied from a solution for something similar
that I found online. I know that they're not doing what I would like to do.
I want $unit to hold the unit the user chose, and $value to hold the value the
user put in. */
?>
</div>
So ideally I want to be able to input for example 20, choose "meters", click convert and then print "0.02 km, 200 dcm, 2000 cm, 20000 mm".
At the moment I'm stuck on this: how can I check which "original unit" got selected? In other words, how can I check if the user chose kilometers or meters or any other unit and edit my output accordingly?
And: how can I print the output?
I know I should somehow use $_POST but I'm not sure how.
Once again, I am not asking for code (although some would be nice ;) ), but for a pointer. I read a book about PHP but it's not very helpful with this.
Thank you in advance. Sorry if I made any mistakes, English isn't my first language.