So, assignment #2 for my PHP/mySQL class was to create a page that will convert a numeric value from Celsius to Fahrenheit or vice versa. I started out this morning writing on my big marker board to write out all the stuff I had to have and process.
That part went pretty smoothly so I sat down to start coding the stuff on the board. But, when I uploaded the file I was in dismay as the calculation functions were obviously doing something, just not the right thing. After a couple of hours on and off it (doing other stuff that actually paid) I finally realized I had left the “$” off of a variable in both calculation functions… AMAZING! No telling how many sets of working code I had been through before discovering that.
So I finally got it working… or so I thought. The page is supposed to issue a error message if the input field is blank or if it has non-numeric input. Mine did that, but it also issued the warning when you loaded the page before any input. UGH! Back to debugging. I finally figured that out and all was going very well… or so I thought…
So when I tried to convert “0″ from either F to C or C to F the page just kind of stared back at me with nothing. I looked over the formulas and saw nothing that could be wrong so I emailed my professor about it. He was kind enough to tell me I had discovered a nuisance in PHP. It seems that “0″ is considered empty by PHP. So, there was nothing to convert, and it was neither empty or non-numeric so it did nothing. First he told me to play with using the === operator (which I had done early on when I was missing the $ in the variables) and then he suggested the is_null() fucntion. Shazaam! Put that on in and all was great… problem solved!
Or, so I thought. Another problem which had always been there, it just was not till now I could test to see it. When you enter 32 F to convert to C the result is seen as… you guessed it… empty by PHP. Now I have that conundrum to solve. Oops.. solved it by using the same is_null() instead of empty() again in the output.
YAY! Done. Here’s the page. Now, wonder if I can give a visual diagram of this output like last week?




And on an interesting note, I was at a restaurant this week sharing lunch with a friend when our server (another friend) came up and told us that until moments before she thought she had seen it all as a server. Seems another server’s table/guests left a $5 bill and a hand full of coupons (some were actually expired). At first we thought the folks had actually left the coupons as the tip. Then when we found out about the $5 bill we were more inclined to believe the guests were merely cleaning out their coupon envelope or something and left those as trash. But, what a funny thought. Anyone out there leave coupons or something other than money as a tip for your server (not counting those of you who leave tracts… I know about that one)?