Hello I'm experimenting with PHP forms and am having trouble getting the form to recognize whether a field has been entered or not. I can't figure out where I'm going wrong. Here's the form, file name register_program.html:
<?php$problem = $_SESSION['problem'];?><form id="regProg" action="verify.php" method="POST"> <?php if ($problem == 2) { echo '<p style="color:red;">Please fill in the form below</p>'; } elseIf ($problem == 1) { echo '<p>Thank you for filling in the form.</p>'; } ?> First Name: <input type="text" name="firstName" id="firstName" value="<?php echo $_SESSION['firstName']; ?>" size="40" maxlength="100" /><br /> <input type="submit" name="submit" value="Submit" /> <input type="submit" name="reset" value="Reset" /></form>
And here's the PHP, file name verify.php:
<?phpsession_start(); if (isset($_POST['reset'])) { session_destroy();}else { $_SESSION['firstName'] = $_POST['firstName']; if (isset($_POST['firstName'])) { $_SESSION['problem'] = 1; $to = "myemail@host.com"; $subject = "Test mail"; $message = "Hello! This is a simple email message."; $from = "Me"; $headers = "From:" . $_POST['firstName']; mail($to,$subject,$message,$headers); } else { $_SESSION['problem'] = 2; }} header('Location: register_program.html');?>
Many thanks,Andy