Jump to content

Undefined index repeating error


ProblemHelpPlease2

Recommended Posts

I have a simple problem but seem to be hitting a roadblock with fixing it.

I am in the process of upgrading a site from PHP 5.6 to 7.0 (eventually to 7.2)

I am seeing error notices like

PHP Notice:  Undefined index: productpage in …..

I know this it because the $_REQUEST can sometimes be empty depending on what data is passed back and when certain pages are loaded

$productpage = mysqli_real_escape_string($con, $_REQUEST['productpage']);

I also know that I could turn the error notice off or use isset to check $_REQUEST but I would prefer to use the ?? '' option to fix this issue.

The problem is that when I add the ?? '' option to the above code the problem resolved itself but then moments later the same error on the same line reappeared in the error logs and I cant understand why.

Can someone give me the correct example of where to place ?? '' in the above code so that I can rule out my potentially dodgy code as being the reason the error keeps reappearing.

 

Link to comment
Share on other sites

When you added the ?? in, what did you end up with? If the error went away at all then you probably did the correct thing

$productpage = mysqli_real_escape_string($con, $_REQUEST['productpage'] ?? 'some reasonable default');

which means the return of the error message means either (a) the change got somehow reverted, or more likely (b) the server is running old code because of a cache.

Assuming you're running php-fpm, try restarting it.

Link to comment
Share on other sites

Well at least I know I had the code correct as its exactly what you have provided.

To answer your question the problem went away on the next run through, I had 5 errors all the same, changed 1 of them to see if it made a difference and then had 4 errors as you would expect.

It was 5 minutes later that the issue reappeared. I checked the code and it still had my change in it.

I wondered if it might be a cache issue but that's harder to check as the site is currently on a server that I don't have full access to. I guess the next step is to make the code change again (I reverted it) and then leave it for 24 hours and see if its still giving me the error in the logs.

Thank you for your help.

Link to comment
Share on other sites

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.