PHP Calculator
by tmac on Jan.22, 2010, under PHP, Personal, Projects
So this evening I set myself a challenge to create a simple PHP calculator. With a little (actually a lot) help from a friend I managed to get the calculator working.
It contains the simple functions of +,/,*and – and also 3 memory slots to save the result which you are able to call back at anytime.
It contains JavaScript too. So allow your browsers to view it.
http://www.tmacuk.co.uk/php/calc/
I will be developing this more and more as I get time, just for practise purposes. I wanted to make the help box invisible until you click the button. I want to create a AC and/or DEL button to remove what is in the result/input boxes. Finally I want to make it look more pretty so at the same time practising my CSS and HTML.
Access to source code will be available eventually. At the moment the code is really messy and quite embarrasing to show.
Thanks
tmacuk
4 Comments for this entry
1 Trackback or Pingback for this entry
-
math1
April 5th, 2010 on 3:58 pm[...] Subversion Branching and Merging. Next Entry Rendering Global t:messages After Redirect. About …PHP Calculator tmacukSo this evening I set myself a challenge to create a simple PHP calculator. … [...]
January 22nd, 2010 on 6:56 pm
When clicking divide (regardless of numbers) get:
Warning: Division by zero in /home/tmacukc/public_html/php/calc/index.php on line 77
Also after this happened it stopped adding up properly even after refreshing so now doesn’t do anything!
January 24th, 2010 on 4:40 pm
tried everything mate and the only time that comes back to me is when i dont insert a number.
January 24th, 2010 on 11:58 pm
Intresting, it still doesn’t work for me, haven’t tried on another browser as dont have one atm, using ubuntu 9.10 and firefox 3.57.
I can see the issue with the sums, if for example I put a number in and press add the URL it navigates too is:
http://www.tmacuk.co.uk/php/calc/?num1=NUMBER_I_ENTERED&Math1=Add&num2=
So num2 is missing and does nothing, if I put a value in num2 it works…
As for the divide by zero error that is because of the lack of num2 in the url, that could be better handled by testing for a 0 input and then just putting the total as ERR as you would get on a normal calculator
January 25th, 2010 on 8:36 am
OK I got it, user error
I didn’t see 2nd text box so was expecting that anything I put in first would have the action I stated by that amount on the total, like a real calculator
Just improve error handling then if your doing it this way!