How to remove ajax image upload notice - php

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;

Related

undefined array warning during isset usage

How can I check if a variable is set in PHP? If I am using isset it still throws an error Warning: Undefined variable
if (isset($_POST['newContext'])) {
$newContext = $_POST['newContext'];
}
Background:
My JavaScript file passing const = newContext to my PHP. This variable is in use like 80% of each executons. I want to get rid of the PHP warning message for the remaining 20% and only set the passed variable if this is not empty. How can I do it?
Had an old loop included, definetely as Eriksson mentioned, it wasn´t the method

Getting Undefined variable: type in laravel

I am getting this message
While trying to load a page. And its indicating to this line of code
return view('admin/vehicle-categories/index',compact('categories','level','parent_categories','type','parent_id'));
}
How can I solve this?
This was a breaking change introduced in PHP 7.2. Previously you could compact a named variable that was not yet defined. After 7.2 you must define the variable previous to adding to the compact method.
Broke a lot of code for us as well.
The fix is to simply define the variable before the compact statement, even if null. Be careful if going through a branch/if-check that you define it for certain:
$type == null // or value

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 Constant Issue

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") { }

"Assigning the return value of new by reference is deprecated" error

The problem is:
Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\FlashChat_v607\chat\inc\common.php on line 155
Notice: Undefined variable: step in C:\wamp\www\FlashChat_v607\chat\inc\common.php on line 94
This is the link where you can find the code:
http://www5.zippyshare.com/v/3592861/file.html
This line:
$GLOBALS['fc_config']['bot'] =& new Bot();
Should be this:
$GLOBALS['fc_config']['bot'] = new Bot();
And the notice on line 94:
if ( $step > 2 || !isset($step) )
That you can probably ignore. You are checking the value of $step, but you never defined that variable. However, since you also explicitly check if it isset I'm guessing you should be fine. Might be better to check isset first though.
Regardless, these are both minor problems. Sounds like the real problem might be that you have E_NOTICE, E_DEPRECATED and error display enabled on a production server, which would be messing up your page displays with error messages.
Try changing the error display options in your php.ini so those don't display (although you would probably want to leave them on for a development box)
The "Assigning the return value of new by reference" is because this idiom is in your code
$foo = &new Bar;
Change it to
$foo = new Bar;
To see why this idiom was used in PHP4, see this manual page.
The NOTICE on line 94 is because...
if ( $step > 2 || !isset($step) )
Should be:
if (!isset($step) || $step > 2 )
This is because you always want to check if the variable exists FIRST, and then check any other values. If $step isn't set, you'll get the NOTCIE you received.

Categories