Jump to content

why does this always throw an error??


markbett

Recommended Posts

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

[code]     <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>[/code]

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

[code]<?
$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();
  }[/code]
Link to comment
https://forums.phpfreaks.com/topic/21029-why-does-this-always-throw-an-error/
Share on other sites

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++;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.