Jump to content


Photo

why does this always throw an error??


  • Please log in to reply
2 replies to this topic

#1 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 17 September 2006 - 01:20 AM

this is suppose to be processing a dynamically created form

i check to make sure the form is creating the right values for the text boxes that are being processed

  	  <table width="60%" border="0" align="center" cellpadding="0">
        <tr>
          <td colspan="2" class="box_title">Guest 1</td>
          </tr>
        <tr>
          <td class="event_text">Name:</td>
          <td><input name="guest_name1" type="text" class="event_desc" id="guest_name1" value="" size="30" maxlength="50"></td>
        </tr>
        <tr>
          <td class="event_text">E-mail Address: </td>
          <td><input name="guest_email1" type="text" class="event_desc" id="guest_email1" size="30"></td>
        </tr>
        <tr>
          <td class="event_text">Confirm Email: </td>
          <td><input name="guest_veri1" type="text" class="event_desc" id="guest_veri1" size="30" maxlength="50"></td>
        </tr>
      </table>

for some reason it always says there is an error though...

<?
		$errors = false;
		$i='1';
		$guests=mysql_real_escape_string($_POST['guests']);
		$guest_array = array();

			while($i<=$guests){
				if(!$_POST[${guest_name.$i}] || 
				   !$_POST[${guest_email.$i}] || 
				   !$_POST[${guest_veri.$i}]){
 						 $error .= "Oops.  It looks like something bad happened when you provided us with".
									" your guests information.";
						 $errors = true; 
				 
						if(!$_POST[${guest_name.$i}]){
							$error .= "You forgot to enter in guest $i's name.\n";
						 }
						if(!$_POST[${guest_email.$i}]){
							$error .= "You forgot to enter in guest $i's email address.\n";
							$email_error = true;
						 }
						if(!$_POST[${guest_veri.$i}]){
							$error .= "You forgot to verify guest $i's email address.\n";
							$email_error = true;
						 }
					} //closes the checks to see that all fields were filled in
	   if($email_error == false){
			 if($_POST[${guest_email.$i}] != 
					  $_POST[${guest_veri.$i}]){
				$errors = true;
				$error .= "The e-mail addresses do not match!\n";
				$email_error = true;
					 }
			   }
	 	//check to make sure the email addresses are valid
		if(validate_email($guest_email1)){
				$errors = true;
				$error .= "The e-mail address for guest $i does not appear to be valid!\n";
				$email_error = true;
				} 
		//all error checking is done
				
				
		//move on to the next guest
				$i++;
				}
		//check to see if an error occured while checking the guests information		
	if($errors == true){
			 $error = nl2br($error);	
			include $_SERVER['DOCUMENT_ROOT'].'/sbqa/html/forms/guests.htm';  //spit them back to the form
			  footer();
			  exit();
 	  }


#2 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 17 September 2006 - 01:27 AM

mmk i think its because the $_POST[${guest_name.$i}] 's are wrong... what should i be using to get the dynamically created POST vaiable values??

#3 markbett

markbett
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 17 September 2006 - 01:41 AM

got it... for those that endevor down a similar path the code that works is:

while($i<=$guests){
if(!$_POST["{guest_name".$i] ||
  !$_POST["guest_email".$i] ||
  !$_POST["guest_veri".$i]){
$error .= "Oops.  It looks like something bad happened when you provided us with".
" your guests information.".$_POST['${guest_name.$i}\n'];
$errors = true;

if(!$_POST["{guest_name".$i]){
$error .= "You forgot to enter in guest $i's name.\n";
}
if(!$_POST["guest_email".$i]){
$error .= "You forgot to enter in guest $i's email address.\n";
$email_error = true;
}
if(!$_POST["guest_veri".$i]){
$error .= "You forgot to verify guest $i's email address.\n";
$email_error = true;
}
} //closes the checks to see that all fields were filled in
  if($email_error == false){
if($_POST["guest_email".$i] !=
  $_POST["guest_veri".$i]){
$errors = true;
$error .= "The e-mail addresses do not match!\n";
$email_error = true;
}
  }
//check to make sure the email addresses are valid
if(validate_email($_POST["guest_veri".$i])){
$errors = true;
$error .= "The e-mail address for guest $i does not appear to be valid!\n";
$email_error = true;
}
//all error checking is done


//move on to the next guest
$i++;
}




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users