15: Exercise Using PHP | Let's Build a Calculator | PHP Tutorial | Learn PHP Programming

44
22



Exercise Using PHP | Let’s Build a Calculator | PHP Tutorial | Learn PHP Programming. In this PHP lesson you will do a short exercise where we use some of the knowledge we have gathered from previous episodes. The primary reason behind this exercise, is to show how we can use what we have learned so far, to build an actual PHP application on our website.

➤ GET ACCESS TO MY LESSON MATERIAL HERE!

First of all, thank you for all the support you have given me!

I am really glad to have such an awesome community on my channel. It motivates me to continue creating and uploading content! So thank you!

I am now using Patreon to share improved and updated lesson material, and for a small fee you can access all the material. I have worked hard, and done my best to help you understand what I teach.

I hope you will find it helpful 🙂

Material for this lesson:

Nguồn:https://wijstaanvooronzegrondrechten.org/

44 COMMENTS

  1. U havent explain GET or isset() yet and u r using it but thats not a big deal but i think u should have explain that in this start of this series

  2. When I hit calculate, nothing happens in the url. Yes my file is saved as a php file and there are no errors popping up. What can the issue be?

  3. You are fantastic! I love your tutorials, thank you so very much. These are well presented, organised, easy to follow/understand. Thank you, thank you, thank you!!!!

  4. i am sure the code is correct ? but dosn't work? help plz
    🙁

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Document</title>
    </head>
    <body>
    <form>
    <input type="text" name="num1" placeholder="write the number1.."><br>
    <select name="operator">
    <option>None</option>
    <option>+</option>
    <option>-</option>
    <option>*</option>
    <option>/</option>
    </select><br>
    <input type="text" name="num2" placeholder="write the number2.."><br>
    <button type="submit" value="submit" name="sumbit">Calculate</button>
    </form>
    <p>Inatija hiya:</p>
    <?php
    if (isset($_GET['submit'])){
    $result1 = $_GET['num1'];
    $result2 = $_GET['num2'];
    $op = $_GET['operator'];
    switch ($operator){
    case "None":
    echo "you need to select a method";
    break;
    case "+":
    echo $result1+$result2;
    break;
    case "-":
    echo $result1-$result2;
    break;
    case "*":
    echo $result1*$result2;
    break;
    case "/":
    echo $result1/$result2;
    break;
    }
    }
    ?>
    </body>
    </html>

  5. I got two errors:

    "Warning: Use of undefined constant None – assumed 'None' (this will throw an Error in a future version of PHP) in C:xampphtdocsphplessonsindex.php on line 33

    Warning: Use of undefined constant Add – assumed 'Add' (this will throw an Error in a future version of PHP) in C:xampphtdocsphplessonsindex.php on line 36

    Do you know why these are popping up?
    I attached code to a code pen

    https://codepen.io/jaylojkigert/pen/XWWEEPb

    Thank You!

  6. Dude, I am not gay or anything "But I love you" I admire people like you who can stop their lives and use their time to share knowledge this way… I always say the way to define people is by looking at their acts based on their knowledge and good will to look after the well being of others. A hug from Guatemala bro, and trust me, if you are not already doing great in life, I am pretty sure you will cause people like you only represent progress.

  7. Hello there and thank you for posting these very interesting videos. I think that so far your tutorials are the most clear and easy to understand. On this particular lesson, I have typed all the html and php code exactly as it is on the correspondent file I downloaded to my computer and as you show on it. Everything is working accordingly. I have the two little text boxes for the num1 and num2 working perfectly. The Calculate button is there looking gorgeous and bright. Everything is ready to go, except that after I enter both numbers, choose an operator and click on the "Calculate" button, nothing happens. I don't get any answer after I perform the Calculate function. What am I doing wrong?

  8. hi did you have a tutorial for the PHP engine setup and which software you used for the webserver you place your php documents on?

  9. Hello guys, here is the solution using if statement instead of the switch. if($operator == "None"){
    echo "True";
    }elseif($operator == "Add"){
    echo $result1 + $result2;
    }elseif($operator == "Subtract"){
    echo $result1 – $result2;
    }elseif($operator == "Multiply") {
    echo $result1 * $result2;
    }else {
    echo $result1 / $result2;
    }
    }

  10. Object not found!

    The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

    If you think this is a server error, please contact the webmaster.

    Error 404
    localhost
    Apache/2.4.39 (Win64) OpenSSL/1.1.1c PHP/7.3.8   please i need a suggestion  on #15 any time i click the button to get the answer it keep poping up this  'obeject not found  and error 404'

  11. I can't make calculations because my folder isn't taking the number. I repeated the code, but I can't do the math operations. Someone can help me?

  12. How come does this channel doesn't have more visibility? Dude you're great! Thank you so much for your videos. Keep up the excellent work!

  13. Guys I'm stuck. I've got all the code right and my Wamp Server is on but it won't out put an answer. Im not sure what Ive done wrong. I even made sure the actual lesson is in the directory. It's pulling the file from my computer and not from the server. Please help.

  14. loved it, it took me 3 days to come to this videos …im a initial advance js learner and i find both php and js similar
    thanks your explanation is great

  15. سلام. دوستان برای یادگیری برنامه نویسی وب به صورت کاربردی و ساده و روون به کانالم سر بزنید. اینم بگم ک کاملا پروژه محور میریم جلو با هم رشد میکنیم…

  16. سلام. دوستان برای یادگیری برنامه نویسی وب به صورت کاربردی و ساده و روون به کانالم سر بزنید. اینم بگم ک کاملا پروژه محور میریم جلو با هم رشد میکنیم…

  17. My button that says "Calculate" doesn't appear. Therefore, I cannot continue.
    Can anyone help me to find the error in the code?

    <!DOCTYPE html>

    <html>

    <head>

    <meta charset="UTF-8">

    <title>Title of the document</title>

    </head>

    <body>

    <form>

    <input type="text" name="num1" placeholder="Number1">

    <input type="text" name="num2" placeholder="Number2">

    <select name="operator">

    <option>None</option>

    <option>Add</option>

    <option>Subtract</option>

    <option>Multiply</option>

    <option>Divide</option>

    </selec>

    <br>

    <button type="submit" name="submit" value="submit">Calculate</button>

    </form>

    </body>

    </html>

    Thanks 🙂

LEAVE A REPLY

Please enter your comment!
Please enter your name here