Jump to content

steph90

New Members
  • Posts

    4
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

steph90's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Sorry, here is the code in the correct form...Please Help!! <html> <title> Pay Calculator </title> <form method='post' action='pay2.php'> First Name: <input type='text' name='first' value="<?php echo ($_POST['first']); ?>" <br/> Last Name: <input type='text' name='last' value="<?php echo ($_POST['last']); ?>" <br/> Hours of Work: <input type='text' name='hours' value="<?php echo ($_POST['hours']); ?>" <br/> Hourly Pay Rate: <input type='text' name='rate' value="<?php echo ($_POST['rate']); ?>" <br/> <input type='submit' value='submit'> </form> </html> <?php $pay = $_POST['pay']; $hours = $_POST['hours']; $extra = $_POST['extra']; $rate = $_POST['rate']; if ($hours > 40){ $extra=$hours-40; $hours=40; $pay=($extra*1.5*$rate)+($hours*$rate); } else { $pay=$hours*$rate; } if (empty($_POST['$first'])) {print "**Please enter your first name\n";} echo "\n Your pay is: <br /> $ $pay <br />" ; ?>
  2. I have created a form where the user enters their first name, last name, work hours, and rate. I want to add a check so that once submit is pressed, the page will return an error if one of the fields was left blank. How can I do it?? I have been trying for hours... Here is my code: <html> <title> Pay Calculator </title> <form method='post' action='pay2.php'> First Name: <input type='text' name='first' value="<?php echo ($_POST['first']); ?>" <br/> Last Name: <input type='text' name='last' value="<?php echo ($_POST['last']); ?>" <br/> Hours of Work: <input type='text' name='hours' value="<?php echo ($_POST['hours']); ?>" <br/> Hourly Pay Rate: <input type='text' name='rate' value="<?php echo ($_POST['rate']); ?>" <br/> <input type='submit' value='submit'> </form> </html> <?php $pay = $_POST['pay']; $hours = $_POST['hours']; $extra = $_POST['extra']; $rate = $_POST['rate']; if ($hours > 40){ $extra=$hours-40; $hours=40; $pay=($extra*1.5*$rate)+($hours*$rate); } else { $pay=$hours*$rate; } if (empty($_POST['$first'])) {print "**Please enter your first name\n";} echo "\n Your pay is: <br /> $ $pay <br />" ; ?>
  3. Thank you for the response, but that does not work. Is there something else that I should be adding in another part of the code?
  4. I cannot figure out how to retain the inputted information once submit is pressed. I want the user to enter their first name, last name, hours of work, and hourly pay rate. Then, I want them to press submit. Their pay will be calculated and displayed, but I still want their inputted information to be visible. How can I do that?? Here is my code: <html> <head> <?php $pay = $_POST['pay']; $hours = $_POST['hours']; $extra = $_POST['extra']; $rate = $_POST['rate']; if ($hours > 40){ $extra=$hours-40; $hours=40; $pay=($extra*1.5*$rate)+($hours*$rate); } else { $pay=$hours*$rate; } echo "Your pay is: <br /> $ $pay <br />" ; ?> </head> <body> <form method='post' action='pay2.php'> First Name: <input type='text' name='first'><br/> Last Name: <input type='text' name='last'><br/> Hours of Work: <input type='text' name='hours'><br/> Hourly Pay Rate: <input type='text' name='rate'><br/> <input type='submit' value='submit'> </form> </body> </html>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.