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>"; ?> Link to comment https://forums.phpfreaks.com/topic/274901-simple-math-problem/ Share on other sites More sharing options...
Jessica Posted February 25, 2013 Share Posted February 25, 2013 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. Link to comment https://forums.phpfreaks.com/topic/274901-simple-math-problem/#findComment-1414746 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. Link to comment https://forums.phpfreaks.com/topic/274901-simple-math-problem/#findComment-1414748 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. Link to comment https://forums.phpfreaks.com/topic/274901-simple-math-problem/#findComment-1414757 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.