kbflowers Posted March 25, 2016 Share Posted March 25, 2016 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 More sharing options...
Larry Posted March 25, 2016 Share Posted March 25, 2016 Just assign the error message to a variable and print the variable where you want the error to appear. Link to comment Share on other sites More sharing options...
kbflowers Posted March 25, 2016 Author Share Posted March 25, 2016 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]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![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]> <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![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 More sharing options...
Larry Posted March 25, 2016 Share Posted March 25, 2016 What does "not work" mean? Also, you haven't done what I suggested in my previous post. Link to comment Share on other sites More sharing options...
kbflowers Posted March 27, 2016 Author Share Posted March 27, 2016 "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? http://127.0.0.1/ch02/phpPaycheck2.php 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 More sharing options...
Larry Posted March 28, 2016 Share Posted March 28, 2016 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 More sharing options...
Recommended Posts