zimbabweo Posted February 24, 2013 Share Posted February 24, 2013 A simple math problem, but I can't get it working. If I enter 50 for $hours and 10 for $hourly I keep getting 400 $weekPay. It refuses to calculate OT pay. I don't understand what's wrong. <?php $name = $_POST['employeeName']; $hours = $_POST['hoursWorked']; $hourly = $_POST['hourlyPay']; echo "<p>Week pay for $name \n</p>"; echo "<p>Hours worked: $hours \n</p>"; echo "<p>Pay rate: $hourly \n</p>"; if ($hours > 40) { $otHours = $hours - 40; echo "<p>OT Hours: $otHours\n</p>"; $weekPay = (($hourly * 40) + (1.5 * hourly) * otHours); } else $weekPay = $hours * $hourly; echo "<p>Week pay: $weekPay </p>"; ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 25, 2013 Share Posted February 25, 2013 (edited) Turn on error reporting and you'd get: Notice: Use of undefined constant hourly - assumed 'hourly' which evals to 0. You've got another one too. A decent editor with syntax highlighting makes it obvious as well. Edited February 25, 2013 by Jessica Quote Link to comment Share on other sites More sharing options...
requinix Posted February 25, 2013 Share Posted February 25, 2013 $weekPay = (($hourly * 40) + (1.5 * hourly) * otHours); Find your php.ini, set display_errors = on error_reporting = -1 then restart your web server and find out what error messages PHP has for that line. Quote Link to comment Share on other sites More sharing options...
zimbabweo Posted February 25, 2013 Author Share Posted February 25, 2013 haha!! Works great now, thanks!! So I was just missing two $ symbols before my variables. Not used to PHP. FYI, i'm using Notepad++. Everything is color coded, but errors don't jump out at me like they do in other IDEs I'm used to. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.