Jalz Posted October 1, 2009 Share Posted October 1, 2009 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 https://forums.phpfreaks.com/topic/176162-trying-to-suppress-undefined-index-error/ Share on other sites More sharing options...
Mark Baker Posted October 1, 2009 Share Posted October 1, 2009 Nothing to do with -> It doesn't like the additional ; if(isset($_REQUEST['firstname'])){$findreq1->AddFindCriterion('MemberForename',$_REQUEST['firstname'];} Link to comment https://forums.phpfreaks.com/topic/176162-trying-to-suppress-undefined-index-error/#findComment-928349 Share on other sites More sharing options...
Jalz Posted October 1, 2009 Author Share Posted October 1, 2009 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 https://forums.phpfreaks.com/topic/176162-trying-to-suppress-undefined-index-error/#findComment-928360 Share on other sites More sharing options...
cags Posted October 1, 2009 Share Posted October 1, 2009 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 https://forums.phpfreaks.com/topic/176162-trying-to-suppress-undefined-index-error/#findComment-928363 Share on other sites More sharing options...
Jalz Posted October 1, 2009 Author Share Posted October 1, 2009 Awesome thankyou guys..... back on my learning journey! Link to comment https://forums.phpfreaks.com/topic/176162-trying-to-suppress-undefined-index-error/#findComment-928380 Share on other sites More sharing options...
SoN9ne Posted October 1, 2009 Share Posted October 1, 2009 It would be more efficient if you fix the class function instead of having to add more redundancy checks. Smarter code is much more efficient and cleaner. Undefined vars are easy to resolve. Link to comment https://forums.phpfreaks.com/topic/176162-trying-to-suppress-undefined-index-error/#findComment-928393 Share on other sites More sharing options...
Jalz Posted October 1, 2009 Author Share Posted October 1, 2009 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 https://forums.phpfreaks.com/topic/176162-trying-to-suppress-undefined-index-error/#findComment-928464 Share on other sites More sharing options...
Jalz Posted October 1, 2009 Author Share Posted October 1, 2009 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 https://forums.phpfreaks.com/topic/176162-trying-to-suppress-undefined-index-error/#findComment-928477 Share on other sites More sharing options...
cags Posted October 1, 2009 Share Posted October 1, 2009 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 https://forums.phpfreaks.com/topic/176162-trying-to-suppress-undefined-index-error/#findComment-928480 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.