Can't get rid of error without breaking search page

10 posts by 2 authors in: Forums > CMS Builder
Last Post: June 2, 2017   (RSS)

By gkornbluth - May 22, 2017

Hi all,

I’ve been playing around for a while and I can’t seem to get rid of the error in a search page without breaking the page (search no longer works) :      

E_NOTICE: Undefined index: save
/home3/ellescho/public_html/dbtproviders/index.php (line 342)
http://dbtproviders.com/index.php



Here’s the code for that line (in red):

// Start Languages Spoken
          @$languagesSpokensearchCriteria = "";  // set default value
          if  (( @$_REQUEST['save'] == 1) && @$_REQUEST['languages_spoken_keyword']) {
           @$languagesSpokensearchCriteria = "<b>Languages Spoken: </b>";  // set default value
           // cycle through each language selected
           foreach ($_REQUEST['languages_spoken_keyword'] as $languagesSpoken) {
            
             // lookup languages spoken number in database
             $languages_listRecord = mysql_get("languages_list", $languagesSpoken);
            
             if ($languages_listRecord) {
               // add "language spoken" value to output
               @$languagesSpokensearchCriteria .= $languages_listRecord['language'] .", ";
             }
            
           }
           
          }
          //End Languages Spoken



I’ve tried things like inserting <?php $save = 0 ?>, <?php $save = "" ?>, <?php $_REQUEST['save'] = 0 ?> and <?php $_REQUEST['save'] = "" ?>  near the top of the page and they stop the error, but the search no longer works.

I’ve attached the complete page code to the post.

I’m sure the solution is something simple, but I can’t seem to find it.

Hope someone can take a look.

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

index.php 38K

By Dave - May 24, 2017

Hi Jerry, 

It's this one: @!$_REQUEST['save'].  You need to suppress errors first: !@$_REQUEST['save']

Broken down processing it from right to left: 

  • $_REQUEST['save'] - check for value of array element with key of 'save', If it's not defined display a warning
  • @ If a warning was produced by the last operation don't show it
  • ! (NOT) check if the last returned value was boolean false (and an undefined array index would return null which evaluates as false)

VS: 

  • $_REQUEST['save'] - check for value of array element with key of 'save', If it's not defined display a warning
  • ! (NOT) check if the last returned value was boolean false (and an undefined array index would return null which evaluates as false)
  • @ If a warning was produced by the last operation don't show it (but this applies to ! now).

Let me know if that works for you.

Dave Edis - Senior Developer
interactivetools.com

By gkornbluth - May 24, 2017

Hi Dave,

Appreciate the feedback. I keep learning something new every day.

I changed the only occurrence of  @!$_REQUEST['save'] to !@$_REQUEST['save'] but that didn't get rid of the error that's produced each time the page loads.

Guess I'm not understanding.

Sorry,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Dave - May 25, 2017

You should be able to check the code on the line number specified.  Also if you're not sure if you're looking at the right variable you can change it to save1, save2, etc.  And then you'll see if the error now references save2.  

Feel free to post the updated error and file if you'd like me to take a look.

Cheers!

Dave Edis - Senior Developer
interactivetools.com

By gkornbluth - May 25, 2017 - edited: May 25, 2017

Hi Dave,

Now I'm really confused...

If I change 'save to 'save2' on line 343, the error on page load goes to the next iteration of 'save' which is on line 363, however the lines of code controlled by the if statement on line 343 don't execute because there is no value for 'save2'

E_NOTICE: Undefined index: save
/home3/ellescho/public_html/dbtproviders/index.php (line 363)
http://dbtproviders.com/

When I change all iterations of 'save' to 'save2' the error on page load on the original line 343 then reads Undefined index: save2

E_NOTICE: Undefined index: save2
/home3/ellescho/public_html/dbtproviders/index.php (line 343)
http://dbtproviders.com/

I don;'t know where to go from here.

The page code is attached

Thanks,

Jerry

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Attachments:

index.php 38K

By Dave - May 31, 2017

Thanks, Jerry!

There's some sort of issue with the error logging where it's logging an error that has already been ignored.  I've patched your version of CMSB and will include the patch in the next release.  You can safely ignore those errors if they're occurring only in the error log.  However, they shouldn't anymore with this patched version.

Hope that helps, let me know if you see any other issues.

Dave Edis - Senior Developer
interactivetools.com

By gkornbluth - June 1, 2017

Thank you Dave,

Glad you discovered the issue.

Can you tell me where you patched the files?

Have a great day.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Dave - June 1, 2017

Hi Jerry, 

For CMSB v3.09, I updated this function in /lib/errorlog_functions.php:

function _errorlog_alreadySeenError($filePath, $lineNum) {
  static $filesToLineNums = [];

  // have we seen this error
  $alreadySeenError = !empty($filesToLineNums[$filePath][$lineNum]);

  // record this as a seen error
  $filesToLineNums[$filePath][$lineNum] = 1;

  //
  return $alreadySeenError;
}

Hope that helps!

Dave Edis - Senior Developer
interactivetools.com

By gkornbluth - June 2, 2017

Hi Dave,

I’ve finally got this working, thanks to all of your help and guidance.

I’ve changed the search form code from:

@$colsToValues['practice_country'] = "\t" . implode("\t", $_REQUEST['practice_country']) . "\t";

to

@$colsToValues['practice_country'] =   ucfirst($_REQUEST['practice_country']) ;

and

<tr>
              <td valign="top">Country</td>
              <td><?php $fieldname = 'practice_country'; ?>
                <?php
if(is_array(@$_REQUEST[$fieldname])){
$fieldValues = $_REQUEST[$fieldname];
}
else{
$fieldValues = explode("\t",trim(@$_REQUEST[$fieldname],"\t"));
}
?>
                <?php $idCounter = 0; ?>
                <?php foreach (getListOptions('accounts', $fieldname) as $value => $label): ?>
                <?php $id = "$fieldname." . ++$idCounter; ?>
                <input type="checkbox" name="<?php echo $fieldname ?>[]" id="<?php echo $id ?>"
value="<?php echo htmlspecialchars($value) ?>" <?php if(in_array($value,$fieldValues)):?> checked="checked" <?php endif ?>/>
                <label for="<?php echo $id ?>"><?php echo htmlspecialchars($label) ?></label>
                <br/>
                <?php endforeach ?></td>
            </tr>

to
<tr>
<td valign="top">Country </td>
<td>
<?php $fieldname = 'practice_country'; ?>
<?php $idCounter = 0; ?>
<?php foreach (getListOptions(accountsTable(), $fieldname) as $value => $label): ?>
<?php $id = "$fieldname." . ++$idCounter; ?>
<input type="radio" name="<?php echo $fieldname ?>" id="<?php echo $id ?>"
 value="<?php echo htmlencode($value) ?>" <?php checkedIf(@$_REQUEST[$fieldname], $value) ?> />
<label for="<?php echo $id ?>"><?php echo htmlencode($label) ?></label><br/>
<?php endforeach ?>
</td>
</tr>

and in the accounts table, to address the fact that the Geocoder plugin doesn't accept multi-value list fields, I changed the field type to a radio button list that gets it’s options from the MySQL query:
SELECT num, category
  FROM `<?php echo $TABLE_PREFIX ?>country_categories`
WHERE hidden = 0
ORDER BY dragSortOrder  ASC ;

Thanks again for everything that you do for us,

Jerry

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php