Jump to content
Larry Ullman's Book Forums

Recommended Posts

Hi,

 

I am currently working on 127.0.0.1/ch02/PHPPaycheck2.html and127.0.0.1/ch02/phpPaycheck2.php.

 
<!php if (!empty($_POST['firstName'])){
$firsName = $_POST['firsName'];
}else{
$firsName =NULL;

 

echo '<p class="error">You forget to enter your first name. Please go back and fill out the form again </p>'
?>
 

An error message "You forget to enter your first name. Please go back and fill out the form again" displays next to <td colspan="2"> First Name</td> in the table of paycheck2.php.

My question is how to make the error massage displaying a separate web page as shown your php textbook page 53-a. but, URL should be in 127.0.0.1/ch02/phpPaycheck2.php. That is an assignment due on this Sunday. If you provide me a clue, that will help me a lot. Thank you. 

Link to comment
Share on other sites

The error echo- $firsName =NULL; -does properly not work.
Would you mind taking a look at below code?  I would like to know what problem I run into.
Thank you for spending time with me. 
 
 
 
 
<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Paycheck Calculator</title>
    <!--[if lt IE 9]>
    <![endif]-->
    <link rel="stylesheet" href="css/styles.css"/>
</head>
<body>
    <!-- PHPPaycheck2.html -->
    <form action="phpPaycheck2.php", method="post"> 
        <fieldset>
           <p>Use this form to calculate the Regular Pay. Overtime Pay, Gross Pay and Net Pay for an employee.</p>
<p><label>First Name<input type="text" name="firstName" id="firstName"/></label></p>
<p><label>Last Name<input type="text" name="lastName" id="lastName"/></label></p>
<p><label>Hours Worked(between0and80)<input type="text" name="hWorked" id="hWorked"/></label></p>
<p><label>Hourly Rate(between7.25and100.00)<input type="text" name="hRate" id="hRate"/></label></p>
<p><input type="submit" value="Calculate" id="submit"/></p>
        </fieldset>
    </form>
</body>
</html>
 
 
!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Paycheck Calculator</title>
<!--[if lt IE 9]>
<![endif]-->
<!--<link rel="stylesheet" href="style.css">-->
<style type="text/css" title="text/css" media="all" >
</head>
<body>
<!--phpPaycheck2.php-->
 
<table id= "employee">
<tr>
<th colspan ="2">Paycheck Calculator</th>
<th> </th>
</tr>
<tr class ="alt">
    <td colspan="2"> First Name</td>
<td class="money">
<?php 
if (!empty($_POST['firstName'])){
$firsName = $_POST['firsName'];
}else{
$firsName =NULL;
echo '<p class="error">You forget to enter your first name. Please go back and fill out the form again </p>'
?>
</td>
</tr>
<tr>
<td colspan="2"> Last Name</td>
<td class="money">
<?php 
$lastName = $_POST['lastName'];
echo $lastName; 
?> 
</td>
    </tr>
<tr> .......

 

</table>

</body>

</html>

Link to comment
Share on other sites

"Just assign the error message to a variable and print the variable where you want the error to appear."

Therefore, I did input as below. This is "assign the error message to a variable" what I understand. 
$firsName =NULL;
echo '<p class="error">You forget to enter your first name. Please go back and fill out the form again </p>'
if you can, would you mind taking a look at below URL? 
The error message should be separated pages in php, but this error messages are the same page above the table.
Link to comment
Share on other sites

To be more explicit, this is what I mean:

$firstNameError = 'You forget to enter your first name. Please go back and fill out the form again.';

And then later:

if (isset($firstNameError)) echo $firstNameError;

I can't view that URL as it's a local site. 127.0.0.1 is only accessible on your computer.

Link to comment
Share on other sites

 Share

×
×
  • Create New...