CS363-U Lab 5

As always, if you can't figure out how to do something, raise your hand. Also, when you are done call over the instructor and show what you have before logging off.

PHP CALCULATOR

  1. Time for another calculator.

  2. Remember your first calculator in this class? It had numbers and four arithmetic functions, and you were really good if you could take input one digit at a time? Let's do that in php today.

    You will have a lot of reason to look at php.net/foo where foo is the function you think php might have. The good thing is that the LHS frame has a list of functions, so your guesses get better and better!

    First, make sure you can display your numeric buttons and the current value. Pressing a numeric key should point to a URL such as mycalc.php?7, and this is easy to pick up as $QUERY_STRING in your php. Or if you want to do less all-caps typing, say href=mycalc.php?i=7 and then $i is your baby.

    You should be able to verify that your numeric keys extend the current value pretty quickly. Next, you need to generate the hidden value in the form upon receiving an arithmetic operator, such as mycalc?op=add. Or if you want to be ambitious, store this value on the server in a file, rather than picking it off of the form. It's a crazy thing to do, but it's good practice using files.

    You might notice that php has a switch statement if you don't want to say if...elseif... elseif... else.

    That's it. You are a lab5 star. However, you might want to get started on your hw5.