Jump to content

trying to suppress undefined index error


Jalz

Recommended Posts

Hi all,

 

I have a search page (a form) with about 5 fields which I send to a response page. The page works great as long as ALL teh fields are entered in, however if a field is left blank, the response page produces a undefined index error on the fields with an empty value.

 

The code I have below might give you an idea of what I am trying to work with....

 


//create request 1
$findreq1->AddFindCriterion('MemberForename',$_REQUEST['firstname']);
$findreq1->AddFindCriterion('MemberFamilyName',$_REQUEST['familyname']);
$findreq1->AddFindCriterion('MemberInitials',$_REQUEST['initials']);
$findreq1->AddFindCriterion('MemberGender',$_REQUEST['gender']);
$findreq1->AddFindCriterion('MemberofSchool::MemberOfSchoolStartTerm',$_REQUEST['start_term']);
$findreq1->AddFindCriterion('MemberofSchool::MemberOfSchoolEndTerm',$_REQUEST['end_term']);
$findreq1->AddFindCriterion('MemberofSchool::BoardingHouseDescription',$_REQUEST['entry_form']);

 

I thought by adding an if statement to identify which fields should be populated would work, so I added the following code

 

if(isset($_REQUEST['firstname'])){$findreq1->AddFindCriterion('MemberForename',$_REQUEST['firstname'];};

 

however it seems to be producing a different erro - syntax error, unexpected ';' in C:\inetpub\wwwroot\alumni\full_search_results.php on line 13.

 

My guess is it does not like the -> character.

 

Any help would be much appreciated.

 

Thanking all in advance.

 

Hi Mark,

 

After I removed the additional ';'

 

I now get the following error. syntax error, unexpected '}' in C:\inetpub\wwwroot\alumni\full_search_results.php on line 13

 

The line now reads

 

if(isset($_REQUEST['firstname'])){$findreq1->AddFindCriterion('MemberForename',$_REQUEST['firstname']};

You took the wrong semicolon out. Mark Baker identified the right semicolon, but missed a close bracket.

 

<?php
if(isset($_REQUEST['firstname'])){
$findreq1->AddFindCriterion('MemberForename', $_REQUEST['firstname']);
}
?>

 

You'd find problems like that an aweful lot easier to spot if you'd have used multiple lines, even if you'd changed it back to single line afterwards

Thanks SoN9ne,

 

I agree would be much more efficient doing it that way. Unfortunately I am using class developed by FileMaker, part of the API for PHP and am restricted so I can't do this without causing hassle for me in the future when it comes to upgrade their API.

 

I'm learning a lot from you guys, php is not my thing but rekon its fairly 'understandable' to pick up, so please bear with me.

 

Anyone know what is wrong with this line, followed more or less the same convention as above... but its the only line now producing an undefined error.

 

if(isset($_REQUEST['starting_year_d'])){$start_year = $findops[$_REQUEST['starting_year_d']].$_REQUEST['starting_year'];}

You are using $_REQUEST['starting_year'] without checking isset that could potentially cause an undefine index error. You would also get the error if the value of $_REQUEST['starting_year_d'] is not eq, gt, lt, neq, gte or lte.

 

 

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.