Friday, February 12, 2021

Weight Converter in PHP

 A program that I wrote in PHP which allows the user to give value in kilograms and pounds  it will convert the given values to kilograms or pounds in vice versa.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod City I also accepting computer repair, networking, and Arduino Project development at a very affordable price. My website is www.jakerpomperada.blogspot.com and www.jakerpomperada.com

If you like this video please click the LIKE button, SHARE, and SUBSCRIBE to my channel.

Your support on my channel is highly appreciated.

Thank you very much.






Program Listing


style.css

* {

    box-sizing: border-box;

}



body {

    font-family: Arial, Helvetica, sans-serif;

    background: #2B2B2B;

    color: #1a1a1a;

    font-size: 15px;

}


main {

    position: absolute;

    top: 50%;

    left: 50%;

    transform: translate(-50%, -50%);

    width: 500px;

    box-shadow: rgba(99, 99, 99, 0.2) 0px 2px 8px 0px;

    border-radius: 10px;

}


.container {

    display: block;

    padding: 30px;

    background: #fff;

    text-align: left;

    border-radius: 10px;

}


.container-wrapper {

    padding: 10px;

}


.container-wrapper:first-of-type {

    margin-bottom: 10px;

}


h1, h2 {

    text-align: center;

}


h1 {

    margin: 10px 0 30px;

}


label {

    width: 100%;

}


input,

select {

    display: inline-block;

    background: #f5f5f5;

    width: 100%;

    margin: 5px 0 20px 0;

    padding: 15px;

    border: none;

    font-size: 15px;

}


input:focus,

select:focus {

    background: #eeeeee;

    outline: none;

}


.btnReset,

button {

    background: #4594E4;

    color: #fff;

    padding: 15px;

    margin: 0 0 20px;

    border: none;

    cursor: pointer;

    width: 100%;

    opacity: 0.9;

    font-size: 15px;

    outline: none;

    border:0;

}


.btnWrapper {

    display: inline-flex;

    margin: 0;

    width: 100%;

}


.btnWrapper input,

.btnWrapper .btnReset,

.btnWrapper .btnConvert {

    padding: 15px;

    border: none;

    font-size: 15px;

    margin: 0;


}

.btnWrapper input {

    width: 100%;

}


.btnReset {

    background: #2E4760;

}


.btnReset,

.btnConvert {

    width: 100px;

    text-align: center;

    text-decoration: none;

}


.btnSelect {

    background: #4EC4A2;

    width: 100px;

}


.btnReset:hover,

button:hover {

    opacity: 1;

}


.answer {

    margin: 20px 0 0;

    width: 100%;

    padding: 20px;

    text-align: center;

    font-size: 30px;

    font-weight: bold;

    background: #dadada;

    font-family: 'Times New Roman', serif;

    line-height: 1.5;

}


.visibility_on {

    display: block;


}


.visibility_off {

    display: none;

}


.frmSelect {  

    display: flex;

    flex-flow: row wrap;

    align-items: center;

}


.frmSelect select {

    vertical-align: middle;

    padding: 15px;

    margin: 5px 0 0;

    width: calc(100% - 100px);

}


.frmSelect button {

    margin: 5px 0 0;

}


.pieText {

    font-family: Serif;

}

.blueText {

    color:#2196f3;

}


index.php


<?php 

    

    $area = $html = $infotext = $sel1 = $sel2 = $sel3 = "";

    $num1 = isset($_POST['txtNum1']) ? floatval($_POST['txtNum1']) : "";

    $visibility = "visibility_off";

    $selUnit = isset($_GET['txtSelectBox']) ? $_GET['txtSelectBox'] : '';


    // Display selected shape input fields

    if(isset($_GET['txtSelectBox'])) {

        $visibility = "visibility_on";


        switch ($selUnit) {

            case "kg2lb":

                $sel1 = "selected";

                $html1 = '<h2>Kilograms &#8594; Pounds Converter</h2>';

                $html2 = '<input type="number" name="txtNum1" id="txtNum1" placeholder="Input weight in kilograms (kg)" value="'.$num1.'" required>';

                if(isset($_POST['btnConvert'])) {

                    $ans = round(($num1 * 2.20462262185), 4);

                    $infotext = '<div class="answer">'.$ans.' kg</div>';

                }

                break;

            case "lb2kg":

                $sel2 = "selected";

                $html1 = '<h2>Pounds &#8594; Kilograms Converter</h2>';

                $html2 = '<input type="number" name="txtNum1" id="txtNum1" placeholder="Input weight in pounds (lb)" value="'.$num1.'" required>';

                if(isset($_POST['btnConvert'])) {

                    $ans = round(($num1 / 2.20462262185), 4);

                    $infotext = '<div class="answer">'.$ans.' lb</div>';

                }

                break;

        }

    }

?>

<!DOCTYPE html>

<html lang="en">

    <head>

        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Weight Converter in PHP</title>

        <link rel="stylesheet" href="style.css">

    </head>

    <body>

        <main>

            <div class="container">

                <h1>Weight Converter in PHP</h1>

                <h2>Jake R. Pomperada, MAED-IT,MIT</h2>

                <div class="container-wrapper">

                    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get" class="frmSelect">

                        <label for="txtSelectBox"><b>Choose the type of unit conversion:</b></label>

                        <select name="txtSelectBox" id="txtSelectBox" value="<?php echo $oper; ?>" required>

                            <option value="kg2lb" <?php echo $sel1; ?>>Kilograms &#8594; Pounds</option>

                            <option value="lb2kg" <?php echo $sel2; ?>>Pounds &#8594; Kilograms</option>

                        </select>


                        <button type="submit" class="btnSelect">Select</button>

                    </form>

                </div>

                <div class="container-wrapper <?php echo $visibility; ?>">

                    <form action="" method="post" class="frmAreaCalculate">

                        <?php echo $html1; ?>

                        

                        <div class="btnWrapper">

                            <?php echo $html2; ?>

                            <a href="index.php" type="button" name="btnReset" class="btnReset">Reset</a>

                            <button type="submit" name="btnConvert" class="btnConvert">Convert</button>

                        </div>


                        <?php echo $infotext; ?>

                    </form>

                </div>

            </div>

        </main>

    </body>

</html>

No comments:

Post a Comment