Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

<!-- What\'s wrong here? The program is supposed to display \"You did not work t

ID: 3734676 • Letter: #

Question

<!--

What's wrong here? The program is supposed to display "You did not work this week" if the hours worked is 0, but it throws an error message instead.

<html>
<head>
   <title>Wage Report</title>
  
</head>
<body>
   <h1>WAGE REPORT</h1>

   <?php
       $hourlyWage = 12.75;
       $hoursWorked = 0;


       if ($hoursWorked == 0)
       {
      
       }
           print("<p>You did not work this week</p>");
       else
       {
           $wage = $hourlyWage * $hoursWorked;
           print("<p>Your hourly wage is $ $hourlyWage and you worked
           $hoursWorked hours.</p>");
           print("<p>Your wages are $ $wage.</p>");
       }

   ?>
</body>
</html>

<--

Explanation / Answer

Answer:

highlighted the mistake with bold text.

<html>
<head>
   <title>Wage Report</title>
</head>
<body>
   <h1>WAGE REPORT</h1>
<?php
       $hourlyWage = 12.75;
       $hoursWorked = 0;
if ($hoursWorked == 0)
       {
       print("<p>You did not work this week</p>"); /* This statement is outside the body of if statement*/
}
       else
       {
           $wage = $hourlyWage * $hoursWorked;
           print("<p>Your hourly wage is $ $hourlyWage and you worked
           $hoursWorked hours.</p>");
           print("<p>Your wages are $ $wage.</p>");
       }
?>
</body>
</html>

Procedure to execute 'php' code inside 'html' or 'htm', for 'apache version 2.4.23'

Go to '/etc/apache2/mods-enabled' edit '@mime.conf'

Go to end of file and add the following line:

"AddType application/x-httpd-php .html .htm"

BEFORE tag '< /ifModules >' verified and tested with 'apache 2.4.23' and 'php 5.6.17-1' under 'debian'

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote