Undefined Constant Issue - php

I was working on my site yesterday and all the content was appearing fine. Then today, I refreshed and something has broken.
I'm getting this error on the homepage:
Notice: Use of undefined constant Page - assumed 'Page' in includes\survey_inside.php on line 19
Notice: Use of undefined constant Listing - assumed 'Listing' in includes\survey_inside.php on line 20
When I look on line 19 the code is:
$strPage = $_REQUEST[Page];
if($_REQUEST[mode]=="Listing"){
Like I said, everything worked fine yesterday, and I didn't change these lines. I've been looking around for several hours and am stuck. Any thoughts on how to proceed with figuring out what happened?
Thanks!

When you want to access an array like $_REQUEST, you have to use some key (string value). In this case you are calling $_REQUEST[Page] and $_REQUEST[mode].
Since Page and mode are not constant values, you have to use it as a string, so:
$strPage = $_REQUEST['Page'];
if ($_REQUEST['mode'] == "Listing") { }

Related

extract($_GET) PHP ends up with undefined variable

I am having trouble with:
Notice: Undefined variable: detail in
/var/www/html/premysl/php/web_f7mysql.php on line 43
The mentioned line contains some condition with $detail == NULL, which (variable $detail) should be extracted via extract($_GET) written in different file.
Here's the thing - whole project is hosted in root of server with PHP 5.4.13 and works perfectly. Anyway, it doesn't run on a different server with PHP 5.3.3 (cli).
Unfortunately it is necessary to make it work on the second one. I guess there's some "compatibility" issue, maybe different settings.
Do you have any sugestions what to focus on?
Your line that reads like this:
$detail == NULL
Should be changed to combine isset and !empty like this:
isset($detail) && !empty($detail)
Also using extract($_GET) is a bit ridiculous. Instead just do this:
$detail = (isset($_GET['detail']) && !empty($_GET['detail'])) ? $_GET['detail'] : null;
Also as far as the actual error goes:
Notice: Undefined variable: detail in /var/www/html/premysl/php/web_f7mysql.php on line 43
Then just stick this line within whatever function is causing this issue in web_f7mysql.php:
global $detail;

Undefined offset issue PHP

I have a variable $newExtract[$x][3]. When I try to explode it as:
explode("/", $newExtract[$x][3])
It gives me error message:
"Notice: Undefined offset: 3 in C:\xampp\htdocs\torrent\classes\sm9.class.php on line 63".
But, when I echo it using echo $newExtract[$x][3]; die();, it gives me the result as 13/08/2012 20:58.
Can anyone help me what is happening? Why, I am not able to explode it?
Thanks
I've seen several places in PHP where implicit string conversion (or string dereferencing, in this case) causes issues and the simplest path to sanity is using an intermediate variable:
$date = $newExtract[$x][3];
explode("/", $date);
It seems to show up more often with certain internal functions, and I usually run into it more with objects and __toString(), but this wouldn't be the first time for this situation, either.

I have this error "Notice: Use of undefined constant test - assumed 'test'."

Notice: Use of undefined constant test - assumed 'test'.
I am not sure where this error came from. I am using the Widget Logic Plugin and is fully updated, but I can't seem to find where this issue is. Has anyone had this issue and know how to resolve it?
The most likely answer is that you have missed a $ on a variable called $test and used test in your code somewhere.
This is hard to verify without your code, but the error message you are referring to is what generally happens when a variable is written without the $ at the start - PHP tries to assume it is a constant of the same name.
The second option is that there is an array index 'test' with the missing quotes, i.e. $array[test] instead of $array['test'].
Edit: If you are not writing any code yourself, and using only using plug-ins, you might want to do two things:
See if you can find the error in their code (search for a variable called test without a $ in front of it
Raise a bug on their site, so that they can update it

How to remove ajax image upload notice

I am doing project in php.I used ajax code to upload the image.
It done nicely, everything is working but display notice and i want 2 remove this notice...
Notice is as follows:
Notice: Undefined variable: errorList in C:\xampp\htdocs\ajax\scripts\ajaxupload.php on line 18 Notice:
Undefined variable: errorList in
C:\xampp\htdocs\ajax\scripts\ajaxupload.php on line 132
i am not understanding what is the meaning of message...
How to remove this Notice?
To remove the notice you must either check is this variable $errorList defined and if it is, then check ajaxupload.php on line 18 and ajaxupload.php on line 132 does it see it there or is it out of the scope.
The other thing you could do is place at the beginning of PHP file ini_set( 'display_errors', 0 );, but this really bad idea since Notice is made to show what you are doing wrong.
Simply define the variables as null before using them, so that by default they will be null until given a value from elsewhere. Variables defined inside an if block or by user input sometimes don't get defined, right? So for them, a default is needed sso that they at least exist even if they aren't given a value.
$errorList = null;

New to programming php, and have seen similar problems

So currently I'm trying to fix up some old code for a stats server for a game (that is definitely outdated, and has been replaced recently with a new version). MUCH of the code is deprecated, so it's kind of guesswork on fixing it right, but I found a section thats completely broken that I have no idea how to fix, and it's causing a fatal error.
The code is as follows
for ($i=0; $i<$armyCount; $i++)
{
$summary['total']['time'] += $armies[0]['time'.$i];
$summary['total']['win'] += $armies[0]['win'.$i];
$summary['total']['loss'] += $armies[0]['loss'.$i];
$summary['total']['score'] += $armies[0]['score'.$i];
$summary['total']['best'] += $armies[0]['best'.$i];
$summary['total']['worst'] += $armies[0]['worst'.$i];
$summary['total']['brnd'] += $armies[0]['brnd'.$i];
}
The errors I get are as follows
Notice: Uninitialized string offset: 0 in C:\xampp\htdocs\dontneedthis\playerstats.inc.php on line 136
Fatal error: Cannot use string offset as an array in C:\xampp\htdocs\dontneedthis\playerstats.inc.php on line 136
I've seen similar questions asked, and seen how they were resolved, but I don't fully understand how it was done, so don't quite know how to go about fixing this one. Any assistance would be awesome, and I fully intend to release the bugfixed and fully working code (whenever I get that done) to the community that remains.
It looks like your $armies[0]['time'.$i] is initialized as an empty string and not as an array (likely $armies= "").
Notice: Uninitialized string offset: 0
That means that php tries to access your string-variable $armies as an array. If the string is non-empty then this would result in getting single letters from that string. But it seems that $armies is an empty string and so getting the letter with index 0 is not possible.
Fatal error: Cannot use string offset as an array
means that the result of the operation above (which showed the notice) cannot be accessed as an array. Remember that $armies is a astring and the first letter of the string was accessed and the result of this attempt will be accessed as an array.
Try resolving how the $armies variable is filled and why its filled the wrong way.
$armies is an empty string, and you are treating it as any array, in an unrecoverable way.
Show us what $armies should look like, what you get when you var_dump($armies);, and the code from where you assigned it, and we'll help you work out what went wrong.

Categories