I am working on a project and wondering if I could get a little help with my code. I am building a paycheck calculator and need to have that calculator work off 2 pages, an HTML p[age with a 2 field form that a user inputs weekly hours worked and their hourly rate, then on the PHP page I need to calculate weekly pay and factor in any overtime. I also need to verify and validate the form entry data to provide error messages if need be. Only one I can think of is if the user doesn’t input an integer. I put together a code I thought would work but it’s not… Any and all input is greatly appreciated. Currently all this is doing for entering “abc” is giving the letters a value of 0.
The first step I would do is check whether a value is set at all, this is really good to do for most checks. I like to do isset(), but I also see some people just put code in try catch blocks to see whether they work or not.
For your wage, you want to also check for floating numbers. Remember int’s are whole numbers. What if they work 25.25 hours? That is pretty common. Also check that hours & wages is a positive number too.
Only place the processing code in a successful if statement, don’t leave it open to process incorrect information. You’re only going to do anything if the conditions are proper.