How do i keep the error messages from displaying until the s

How do i keep the error messages from displaying until the submit button has been clicked?

html>
<head>
<title>
Paycheck Calculator
</title
</head>
<link rel=\"stylesheet\" href=\"css/styles.css\">
<body>
Use this form to calculate the Regular pay.</br> Overtime Pay. gross pay and net pay for an employee.
<form method=\"post\" action=\"paycheck.php\" >
<fieldset>
<div><label for=\"first\">First Name</label><input type=\"text\" name=\"first\" id=\"first\"></div>
<div><label for=\"last\">Last Name</label><input type=\"text\" name=\"last\" id=\"last\"> </div>
<div><label for=\"hours\">Hours Worked <br> (Between 0 and 80)</label><input type=\"text\" name=\"hours\" id=\"hours\"> </div>
<div><label for=\"rate\">Hourly Rate <br>(Between 0 and 100)</label><input type=\"text\" name=\"rate\" id=\"rate\"> </div>
<div><input type=\"submit\" value=\"Submit\" id=\"submit\"></div>
</fieldset>
</form>
<div>
</body>
</html>

<link rel=\"stylesheet\" href=\"css/styles.css\">
<?php
if(!empty($_POST[\'first\']))
{
$firstname=$_POST[\'first\'];
}
else
{
$firstname= NULL;
echo \"You forgot to enter your first name\".\"</br>\";
$a=0;
}
if(!empty($_POST[\'last\']))
{
$lastname=$_POST[\'last\'];
}
else
{
$lastname= NULL;
echo \"You forgot to enter your Last name\".\"</br>\";
$a=0;
}
if(!empty($_POST[\'hours\']))
{
$hours=$_POST[\'hours\'];
if($hours < 0 || $hours >80)
{
echo \"You must enter Hours Worked that is between 0 to 80.\".\"</br>\";
$a=0;
}
}
else
{
$hours= NULL;
echo \"You must enter Hours Worked that is between 0 to 80.\".\"</br>\";
$a=0;
}
if(!empty($_POST[\'rate\']))
{
$hourlyrate=$_POST[\'rate\'];
if($hourlyrate < 0.00 || $hourlyrate > 100.00)
{
echo \"You must enter Hourly rate that is between 0.00 to 100.00\".\"</br>\";
$a=0;
}
}
else
{
$hourlyrate= NULL;
echo \"You must enter Hourly rate that is between 0.00 to 100.00\".\"</br>\";
$a=0;
}
if(isset($a))
{
echo \"</br>\".\"Please go back and fill out form again\".\"</br>\";
exit(0);
}
  
$ficarate = 5.65;
$federalrate = 5.75;
$staterate = 28;
$employeename = $firstname.\" \".$lastname;
$regularpay = $hours * $hourlyrate;
if ($hours > 40){
$overtime = $hours - 40;
}
else {
   $overtime = 0;
}
$overtimepay = ($overtime * 1.5) * $hourlyrate;
$grosspay = $regularpay + $overtimepay;
$statetax = ($staterate / 100) * $grosspay;
$federaltax = ($federalrate / 100) * $grosspay;
$ficatax = ($ficarate / 100) * $grosspay;//
$totaltax = ($ficarate + $staterate + $federalrate) ;
$netpay = ($grosspay - $totaltax);

$hours = number_format ($hours,2);
$regularpay = number_format($regularpay,2);
$overtimepay = number_format ($overtimepay, 2);
$overtime = number_format ($overtime, 2);
$hourlyrate = number_format ($hourlyrate,2);
$ficarate = number_format($ficarate, 2);
$ficatax = number_format ($ficatax,2);
$staterate = number_format($staterate,2);
$statetax = number_format($statetax,2);
$federalrate = number_format($federalrate, 2);
$grosspay = number_format($grosspay, 2);
$netpay = number_format($netpay, 2);
$totaltax = number_format($totaltax,2);
?>
<table id=\"customer\" >
<tr>
<th>Paycheck Calculator<th>
</tr>
<tr>
<td>Employee Name</td>
<td><?php echo $employeename; ?></td>
</tr>
<tr>
<td>Regular Hours Worked (between 0 and 40)</td>
<td><?php echo $hours; ?></td>
</tr>
<tr>
<td>Overtime Hours Worked(between 0 and 40)</td>
<td><?php echo $overtime; ?></td>
</tr>
<tr>
<td>Hourly Rate</td>
<td>$<?php echo $hourlyrate; ?></td>
</tr>
<tr>
<td>Regular Pay</td>
<td> $<?php echo $regularpay; ?></td>
</tr>
<tr>
<td>Overtime Pay</td>
<td>$<?php echo $overtimepay; ?></td>
</tr>
<tr>
<td>Gross Pay</td>
<td>$<?php echo $grosspay; ?></td>
</tr>
<tr>
<td>Fica Tax Rate</td>
<td><?php echo $ficarate; ?>%</td>
</tr>
<tr>
<td>Fica Taxes Withheld</td>
<td>$<?php echo $ficatax; ?></td>
</tr>
<tr>
<td>State Tax Rate</td>
<td><?php echo $staterate ; ?>%</td>
</tr>
<tr>
<td>State Taxes Withheld</td>
<td>$<?php echo $statetax; ?></td>
</tr>
<tr>
<td>Federal Tax Rate</td>
<td><?php echo $federalrate ; ?>%</td>
</tr>
<tr>
<td>Federal Tax Withheld</td>
<td>$<?php echo $federaltax; ?></td>
</tr>
<tr>
<td>Total Taxes</td>
<td><?php echo $totaltax; ?>%</td>
</tr>
<tr>
<td>Net Pay</td>
<td>$<?php echo $netpay; ?></td>
</tr>
</table>

Solution

The error reporting function error_reporting() specifies the reported errors in the php page.

To enable the reporting of errors set the error_reporting() function with the value E_ALL, i.e error_reporting(E_ALL)

To disable the reporting of errors set the error_reporting() function with 0, i.e error_reporting(0)

Also check the attribute display_errors = on in php.ini file

Finally in the above code, add the following

How do i keep the error messages from displaying until the submit button has been clicked? html> <head> <title> Paycheck Calculator </title &l
How do i keep the error messages from displaying until the submit button has been clicked? html> <head> <title> Paycheck Calculator </title &l
How do i keep the error messages from displaying until the submit button has been clicked? html> <head> <title> Paycheck Calculator </title &l
How do i keep the error messages from displaying until the submit button has been clicked? html> <head> <title> Paycheck Calculator </title &l

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site