webdevdea Posted June 17, 2013 Share Posted June 17, 2013 I need this to only print the little note at the bottom if the user has put in all the information.. Help please.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Assignment2</title> </head> <body> <h3>Personal Information </h3> <?php $chkErrors = FALSE; if(!empty($_POST['fName']) && isset($_POST['fName'])) { } else { echo 'First Name Fieldis empty'; } if(!empty($_POST['lName']) && isset($_POST['lName'])) { } else { echo 'Your last name field is empty'; } if(!empty($_POST['city']) && isset($_POST['city'])) { } else { echo 'Your city field is empty'; } if(!empty($_POST['state']) && isset($_POST['state'])) { } else { echo 'Your state field is empty'; } if(!empty($_POST['zipCode']) && isset($_POST['zipCode'])) { } else { echo 'Your zipcode field is empty'; } { $fName = filter_input(INPUT_POST, "fName"); $lName = filter_input(INPUT_POST, "lName"); $city = filter_input(INPUT_POST, "city"); $state = filter_input(INPUT_POST, "state"); $zipCode = filter_input(INPUT_POST, "zipCode"); } if($chkErrors == FALSE) { echo <<<HERE <h3> Hi there, $fName $lName, <br /> so you live in $city,<br /> in the great state of $state.<br /> I hear the climate around $zipCode is great this time of year. <br /> $fName, I hear that $state has alot to offer as far as recreation goes.<br />I hope that you have a great summer in $city. <br /></h3> HERE; } Quote Link to comment Share on other sites More sharing options...
trq Posted June 17, 2013 Share Posted June 17, 2013 Then somewhere along the line, when you encounter an error you need to set $chkErrors to true. Quote Link to comment Share on other sites More sharing options...
webdevdea Posted June 17, 2013 Author Share Posted June 17, 2013 The HTML and the PHP attached, now its jacked up now when I run it if you do put something in the field. its says you didnt.. Then somewhere along the line, when you encounter an error you need to set $chkErrors to true. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Assignment3</title> </head> <body> <h3>Personal Information </h3> <?php $chkErrors == TRUE; $fName = filter_input(INPUT_POST, "fName"); if(!empty($_POST['fName']) && isset($_POST['fName'])){ print "Go back and put a name in"; $chkErrors ==FALSE; } $lName = filter_input(INPUT_POST, "lName"); if(!empty($_POST['lName']) && isset($_POST['lName'])){ print "Go back and put a lname in"; $chkErrors == FALSE; } $city = filter_input(INPUT_POST, "city"); if(!empty($_POST['city']) && isset($_POST['city'])){ print "Go back and put acity in"; $chkErrors ==FALSE; } $state = filter_input(INPUT_POST, "state"); if(!empty($_POST['state']) && isset($_POST['state'])){ print "Go back and put astate in"; $chkErrors == FALSE; } $zipCode = filter_input(INPUT_POST, "zipCode"); if(!empty($_POST['zipCode']) && isset($_POST['zipCode'])){ print "Go back and put zip in"; $chkErrors ==FALSE; } if ($chkErrors == FALSE){ echo <<<HERE <h3> Hi there, $fName $lName, <br /> so you live in $city,<br /> in the great state of $state.<br /> I hear the climate around $zipCode is great this time of year. <br /> $fName, I hear that $state has alot to offer as far as recreation goes.<br />I hope that you have a great summer in $city. <br /></h3> HERE; } ?> </body> </html> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html lang="EN" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Assignment2</title> <link rel = "stylesheet" type = "text/css" href = "whatsName.css" /> </head> <body> <h1>What's your name?</h1> <h3>Writing a form for user input</h3> <form method = "POST" action = "http://localhost/Assignments php class/Assignment3.php"> <fieldset> <label> Please type your first name: </label> <input type = "text" name = "fName" value = "" /> <br /> <label> Please type your Last name: </label> <input type = "text" name = "lName" value = "" /> <br /> Please type your city: <input type = "text" name = "city" value = "" /> <br /> Please type your State: <input type = "text" name = "state" value = "" /> <br /> Please type your Zipcode: <input type = "text" name = "zipCode" value = "" /> <br /> <input type = "submit" /> </fieldset> </form> </body> </html> Quote Link to comment Share on other sites More sharing options...
webdevdea Posted June 17, 2013 Author Share Posted June 17, 2013 THis example is per the teachers instructions.. it does not work.. <?php $correct = TRUE; $fName = filter_input(INPUT_GET, "fName"); if((!isset($_GET['fName']) or ($_GET['fName'] == ""))) { print "You did not give me a name 1"; $correct = FALSE; } $lName = filter_input(INPUT_GET, "lName"); if((!isset($_GET['lName']) or ($_GET ['lName'] == ""))) { print "You did not give me a name 2"; $correct = FALSE; } $city = filter_input(INPUT_GET, "city"); if((!isset($_GET['lcity']) or ($_GET ['city'] == ""))) { print "You did not give me a name city"; $correct = FALSE; } $state = filter_input(INPUT_GET,"state"); if((!isset($_GET['state']) or ($_GET ['state'] == ""))) { print "You did not give me a name state"; $correct = FALSE; } $zipCode = filter_input(INPUT_GET, "zipCode"); if((!isset($_GET['zipCode']) or ($_GET ['zipCode'] == ""))) { print "You did not give me a name zip"; $correct = FALSE; } if ($correct == TRUE) { echo "Welcome $fName, $lName,$city $state $zipCode"; } ?> Quote Link to comment Share on other sites More sharing options...
boompa Posted June 17, 2013 Share Posted June 17, 2013 it does not work It does not work how exactly? Quote Link to comment Share on other sites More sharing options...
Solution Zulumander Posted June 17, 2013 Solution Share Posted June 17, 2013 (edited) <?php if(isset($_GET['Type'])) { $valid = true; //First, delcarations $fName = filter_input(INPUT_GET, "fName"); $lName = filter_input(INPUT_GET, "lName"); $city = filter_input(INPUT_GET, "city"); $state = filter_input(INPUT_GET, "state"); $zipCode = filter_input(INPUT_GET, "zipCode"); //Array with GET "Names" $GetArray = array('fName', 'lName', 'city', 'state', 'zipCode'); $begin = 0; //ErrMsg Base $errMsgs = "Sorry, something's wrong with your Data Input! <ul>"; //Start the Check for Empty Data input while($begin < count($GetArray)) { if(!$_GET[$GetArray[$begin]]) { //Field was Empty, return false... $valid = false; //And extend the Error Message. $errMsgs .= "<br><li>You did not provide ".$GetArray[$begin]."</li> "; } $begin += 1; } //End the Error message $errMsgs .= "</ul>"; //Final Check if ($valid == true) { echo "Welcome {$fName}, {$lName},{$city} {$state} {$zipCode}"; } else { echo $errMsgs; } } ?> <form action="script.php" method="get"> <input type="hidden" name="Type" value="z"> <input type="text" name="fName"> <input type="text" name="lName"> <input type="text" name="city"> <input type="text" name="state"> <input type="text" name="zipCode"> <input type="submit" value="Submit"> </form> Worked fine for me. Results Sorry, something's wrong with your Data Input! You did not provide fName You did not provide lName You did not provide state Welcome This, Is,A Test Script Edited June 17, 2013 by Zulumander Quote Link to comment 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.