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.

 

Link to comment
Share on other sites

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']};

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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'];}

Link to comment
Share on other sites

Sorry can't modify my last reply, but wanted to add that I have the following array setup for the code that is causing me trouble.

 

$findops = array('eq' => '==','gt' => '>','lt' => '<','neq' => '<>','gte' => '>=','lte' => '<=');

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.