myironworkers Posted March 8, 2013 Share Posted March 8, 2013 Below is my code and the end of the program is all my problems.... I hopeful its only a problem but knowing my luck its more than just one thing... <?php//Validation functions are located in a separate file so they can be reused//on several php pages.session_start(); include_once('ValidationUtilities.php'); //retrieve values from form$firstName = filter_input(INPUT_GET,'firstName');$lastName = filter_input(INPUT_GET,'lastName');$age = filter_input(INPUT_GET,'age');$email = filter_input(INPUT_GET,'email');$state = filter_input(INPUT_GET,'state'); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Validate User Inputs</title> <link href="styles_validate.css" rel="stylesheet" type="text/css"> </head> <body><div class="pageContainer"> <h2>Validate User Inputs</h2><hr><?php $pageValid = true; $postback = $_GET['postback']; if ($pageValid == true && $postback)?> <form> <?php $firstName = $_GET['firstName']; ?> Please enter your first name:<br> <input type="text" name="firstName" size="25" value="<?php echo "$firstName"; ?>"><br> <?php echo "" . fValidateName($firstName) . ""; ?> <?php $lastName= $_GET['lastName']; ?> Please enter your last name:<br> <input type="text" name="lastName" size="25" value="<?php echo "$lastName"; ?>"><br> <?php echo "" . lValidateName($lastName) . ""; ?> <?php $age= $_GET['age']; ?> Please enter your age (13-99):<br> <input type="text" name="age" size="5" value="<?php echo "$age"; ?>"><br> <?php echo "" . fIsAge($age) . ""; ?> <?php $email= $_GET['email']; ?> Please enter your email address:<br> <input type="text" name="email" size="25" value="<?php echo "$email"; ?>"><br> <?php echo "" . fIsEmail($email) . ""; ?> <?php $state= $_GET['state']; ?> Please enter your state abbreviation:<br> <input type="text" name="state" size="2" value="<?php echo "$state"; ?>"><br> <?php echo "" . fIsStateAbbr($state) . ""; ?> <input type="hidden" name="postback" value="true"> <input type="submit" value="Submit your info!"> </form> <?php //$PageIsValid$PageIsValid is a flag to indicate if all form items are valid if($IsPostBack && $IsValidPage) echo "<h3>Success</h3>"; ?> <p><a href="Validate.php"?">Reload page</a></p> </div></body></html> <?php// Validation functions// All functions return true or false //Name Validationfunction fValidateName($firstName) { if ($postback && strlen($firstName) == 0) { echo "<font color='red'>Please enter your first name (alpha characters only)</font>"; $pageValid = false; }}function lValidateName($lastName) { if ($postback && strlen($lastName) == 0) { echo "<font color='red'>Please enter your last name (alpha characters only)</font>"; $pageValid = false; }}//Age Validationfunction fIsAge($age) { if ($postback && ($age<13||$age>99)||strlen($age) == 0) { echo "<font color='red'>Please enter a valid age (13-99) </font>"; $pageValid = false; }}//Email Validationfunction fIsEmail($email) { $pattern = "^[\w!#$%*_\-/?|\^\{\}'~\.]+@(\w+\.)+\w{2,4}^"; if ($postback && !(preg_match($pattern, $email))) { echo "<font color='red'>Please enter a valid email address (xx@xx.xxx)</font>"; $pageValid = false; }}//State Validationfunction fIsStateAbbr($state){$ValidAbbr = array("AL","AK","AZ","AR","CA","CO","CT","DE","FL","GA","HI","ID","IL", "IN","IA","KS","KY","LA","ME","MD","MA","MI","MN","MS","MO","MT","NE","NV","NH", "NJ","NM","NY","NC","ND","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VT", "VA","WA","WV","WI","WY"); $state = strtoupper($state); //in_array() checks if a value exists in an array. if (in_array($state, $ValidAbbr)) { } else {echo "<font color='red'>Please enter a valid state abbreviation</font>"; $pageValid = false; }} ?> then my output is: Validate User Inputs Notice: Undefined index: postback in C:\xampp\htdocs\web3\validate.php on line 33 Top of Form Notice: Undefined index: firstName in C:\xampp\htdocs\web3\validate.php on line 38Please enter your first name:Notice: Undefined variable: postback in C:\xampp\htdocs\web3\ValidationUtilities.php on line 9Notice: Undefined index: lastName in C:\xampp\htdocs\web3\validate.php on line 47Please enter your last name:Notice: Undefined variable: postback in C:\xampp\htdocs\web3\ValidationUtilities.php on line 15Notice: Undefined index: age in C:\xampp\htdocs\web3\validate.php on line 57Please enter your age (13-99):Notice: Undefined variable: postback in C:\xampp\htdocs\web3\ValidationUtilities.php on line 22Please enter a valid age (13-99)Notice: Undefined index: email in C:\xampp\htdocs\web3\validate.php on line 68Please enter your email address:Notice: Undefined variable: postback in C:\xampp\htdocs\web3\ValidationUtilities.php on line 30Notice: Undefined index: state in C:\xampp\htdocs\web3\validate.php on line 78Please enter your state abbreviation:Please enter a valid state abbreviation Bottom of Form Notice: Undefined variable: IsPostBack in C:\xampp\htdocs\web3\validate.php on line 93 Reload page Quote Link to comment https://forums.phpfreaks.com/topic/275419-undefined-errors-cannot-get-user-report-right/ Share on other sites More sharing options...
gristoi Posted March 11, 2013 Share Posted March 11, 2013 you have got no conditional logic around any of your get variables, so when you first load the form none of these will exist. you need to do something along the lines of: <?php if(array_key_exists('firstName', $_GET)){ $firstName = $_GET['firstName']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/275419-undefined-errors-cannot-get-user-report-right/#findComment-1417938 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.