fishswim Posted July 18, 2011 Share Posted July 18, 2011 I am working thru chapter 8, page 214 and supplementing my own code to see what works. If i have a separate conditional for each $_POST[] array first_name, last_name, email etc and then place the conditional to print out the values at the bottom before the closing bracket that began with the first initial conditional, i do receive error messages as shown below in the first code example. Why would that be. If each conditional to print out the value from the $POST array can print out its value in its own conditional, following a conditional using the same index in its own conditional. Or put another way. If there is one value from a html form in a post array and that value can be accessed in a conditional. why is that value not available several conditional`s below its first iteration. does this particular situation have something to do with " stack " or is the stack, [deal with] functions only. Thank you in advance for any response. // the error messages: //Notice: Undefined index: first_name in /somewhere/ qC_stickyRegister.php on line 73 //Notice: Undefined index: last_name in /somewhere/qC_stickyRegister.php on line 78 //Notice: Undefined index: email in /somewhere/qC_stickyRegister.php on line 83 if(!empty($_POST['submitted'])) { $problem = FALSE; if(empty($_POST['first_name'])) { $problem = TRUE; print'<p class="error">Please enter a first name.</p>'; } //---------------------------------------- if(empty($_POST['last_name'])) { $problem = TRUE; print'<p class="error">Please enter a last name</p>'; } //--------------------------------------- if(empty($_POST['email'])) { $problem = TRUE; print'<p class="error">Please enter your e mail address</p>'; } //------------------------------------------- if(empty($_POST['password1'])) { $problem = TRUE; print'<p class="error">Please provide a password.</p>'; } //----------------------------------------- if($_POST['password1'] != $_POST['password2']) { $problem = TRUE; print'<p class="error">Your passwords do not match.</p>'; } //------------------------------------------------------------------------------ if(!$problem) { print'<p>Registration is good.</p>'; $_POST = array(); } else { print'<p class="error">Something went wrong</p>'; } // ----------CONDITIONALS TO PRINT OUT THE VALUES ------------------ if($_POST['first_name'] == TRUE) { $Fname = $_POST['first_name']; print "<p>If the following information is correct please press proceed. <br />First Name: $Fname <br />"; } if($_POST['last_name'] == TRUE) { $Lname = $_POST['last_name']; print "Last Name: $Lname <br />"; } if($_POST['email'] == TRUE) { $mailE = $_POST['email']; print "E mail Address: $mailE </p>"; } } And This Does Work ... if(!empty($_POST['submitted'])) { $problem = FALSE; //------------------------------ if(empty($_POST['first_name'])) { $problem = TRUE; print'<p class="error">Please enter a first name.</p>'; } //------------------------------- if($_POST['first_name'] == TRUE) { $Fname = $_POST['first_name']; print "<p>If the following information is correct please press proceed. <br />First Name: $Fname <br />"; } //---------------------------------------------------------------- if(empty($_POST['last_name'])) { $problem = TRUE; print '<p class="error"Please enter a Last name</p>'; } //------------------------------- if($_POST['last_name'] == TRUE) { $Lname = $_POST['last_name']; print "Last Name: $Lname <br />"; } //------------------------------------------------------------------------------ if(empty($_POST['email'])) { $problem = TRUE; print'<p class="error">Please enter your e mail address</p>'; } //-------------------------------- if($_POST['email'] == TRUE) { $mailE = $_POST['email']; print "E mail Address: $mailE </p>"; } //-------------------------------------------------------------------------- if(empty($_POST['password1'])) { $problem = TRUE; print'<p class="error">Please provide a password.</p>'; } if($_POST['password1'] != $_POST['password2']) { $problem = TRUE; print'<p class="error">Your passwords do not match.</p>'; } if(!$problem) { print'<p>Registration is good.</p>'; $_POST = array(); } else { print'<p class="error">Something went wrong</p>'; } } Link to comment Share on other sites More sharing options...
Josee Posted July 18, 2011 Share Posted July 18, 2011 I think with this: if(!$problem) { print'<p>Registration is good.</p>'; $_POST = array(); } you are reinitializing, i.e. creating a new empty POST array. So after this line $_POST['first_name'] and the others are FALSE. Link to comment Share on other sites More sharing options...
fishswim Posted July 20, 2011 Author Share Posted July 20, 2011 Thank you For the the reply. I think with this: if(!$problem) { print'<p>Registration is good.</p>'; $_POST = array(); } you are reinitializing, i.e. creating a new empty POST array. So after this line $_POST['first_name'] and the others are FALSE. Link to comment Share on other sites More sharing options...
Recommended Posts