[FX.php List] Undefined Index Error

Steve Winter steve at bluecrocodile.co.nz
Mon Aug 13 13:16:15 MDT 2007


Hi Trish,

In that case I'd suggest considering this approach;

1. Declare an array which contains all of your checkbox  field names
2. loop through that array and see if their value is set in $_POST, and if
so do whatever...

Perhaps something like

$checkBoxes = array("field1","field2","field3","....","field20");
foreach($checkBoxes as $checkBox) {
  if(isset($_POST[$checkBox)) {
    // do whatever you need to
  }
}

I'm picking that the 'whatever' is add the fields to your db, so the
whatever might become something like;
    $dbQuery -> AddDBParam($checkBox, $_POST[$checkBox]);

Let us know how you get on...

Cheers
Steve

-----Original Message-----
From: fx.php_list-bounces at mail.iviking.org
[mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of VanBuskirk,
Patricia
Sent: Monday, 13 August 2007 5:22 p.m.
To: FX.php Discussion List
Subject: FW: [FX.php List] Undefined Index Error

Thanks Steve! That does make sense.  

You were correct in your presumption ... the checkbox fields are part of
an array of a $_POST.  

I have about 20 checkboxes on the form, so which solution do you think
would require less typing ... or would it be pretty equal?

Trish


-----Original Message-----
From: fx.php_list-bounces at mail.iviking.org
[mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of Steve Winter
Sent: Monday, August 13, 2007 12:08 PM
To: 'FX.php Discussion List'
Subject: RE: [FX.php List] Undefined Index Error

Hi Patricia,

I presume that this is an index in $_REQUEST or $_POST.

Basically what's happening here is if the checkbox isn't checked, then
there
is no 'value' for BasicSvc_Features.

If you had a regular input field, then it would be something like;
  <input type="text" name="BasicSvc_Features" value="" />
So you're explicitly defining the presence of that variable, but giving
it
an initial null value, so it is defined, but has no value...

With a check box, if the box isn't checked, then when the form is
submitted,
its name is not parsed in as it has no value associated with it... try
doing
a print_r($_REQUEST) and you'll see that un-checked check boxes aren't
in
that list...

Two solutions spring to mind;
  1. check and see if the variable is defined before trying to use it;
	if(isset($_REQUEST['BasicSvc_Features'])) { // whatever }
  2. define an 'unchecked' value in your form,
	<input type="hidden" name="BasicSvc_Features"
id="BasicSvc_Features_unchecked" value="no" />
	<input type="checkbox" name="BasicSvc_Features"
id="BasicSvc_Features_checked" value="yes" />
This way, BasicSvc_Features will always have a value associated with it,
either no, if the box isn't checked, or yes if the box is. Then on your
submission page you can decided what to do based on its value...

Hope this makes sense... let me know if not, or you have problems..

Cheers
Steve

-----Original Message-----
From: fx.php_list-bounces at mail.iviking.org
[mailto:fx.php_list-bounces at mail.iviking.org] On Behalf Of VanBuskirk,
Patricia
Sent: Monday, 13 August 2007 4:43 p.m.
To: FX.php Discussion List
Subject: [FX.php List] Undefined Index Error

Has anyone else had any problems using php with FMP 9 in getting the
following type error:

Notice: Undefined index: BasicSvc_Features in
C:\Inetpub\wwwroot\Forms\TSR\orderconfirm.php on line 14

NOTE:  I only receive this error if any CHECKBOXES are left unchecked on
the form.  Then I will receive one line for each checkbox left
unchecked.  Any other type field left blank will not produce this error.
_______________________________________________
FX.php_List mailing list
FX.php_List at mail.iviking.org
http://www.iviking.org/mailman/listinfo/fx.php_list

No virus found in this incoming message.
Checked by AVG Free Edition. 
Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date:
12/08/2007
11:03 a.m.
 

No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date:
12/08/2007
11:03 a.m.
 


_______________________________________________
FX.php_List mailing list
FX.php_List at mail.iviking.org
http://www.iviking.org/mailman/listinfo/fx.php_list
_______________________________________________
FX.php_List mailing list
FX.php_List at mail.iviking.org
http://www.iviking.org/mailman/listinfo/fx.php_list

No virus found in this incoming message.
Checked by AVG Free Edition. 
Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date: 12/08/2007
11:03 a.m.
 

No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.476 / Virus Database: 269.11.15/949 - Release Date: 12/08/2007
11:03 a.m.
 




More information about the FX.php_List mailing list