Trouble With PHP Errors - php

I am working with my website, and have just have completed it successfully. This website is for payment process. Everything works fine even though am getting errors. What can I do to fix them?
Here are the errors:
Notice: Constant FIRSTNAME already defined in E:\wamp\www\david\include\variables.php on line 42
Notice: Constant LASTNAME already defined in E:\wamp\www\david\include\variables.php on line 43
Notice: Constant EMAIL already defined in E:\wamp\www\david\include\variables.php on line 44
Notice: Constant ADDRESS1 already defined in E:\wamp\www\david\include\variables.php on line 45
Notice: Constant ADDRESS2 already defined in E:\wamp\www\david\include\variables.php on line 46
Notice: Constant CITY already defined in E:\wamp\www\david\include\variables.php on line 47
Notice: Constant POSTCODE already defined in E:\wamp\www\david\include\variables.php on line 48
it comes untill the 63 lines..
How can I fix this?

Your are just including the file twice where these constants are defined.
Check and include them once.
if you are including the file use
require_once('constants.php')
instead of include()

The code is trying to re-define constants somewhere, an action that is not allowed (hence the name "constants").
My guess is that the same file is getting included more than once somewhere. Look through your code to find out what file defines those constants, and then find out what places it's included.
You should also use include_once instead of include. include_once checks to make sure it hasn't been included already. See the manual here:
http://php.net/include-once

Check to see if you are including the same thing twice in your .php page.

you can turn off error reporting at run time using error_reporting(0);

Related

PHP find which file a Constant was initially defined?

I am just wondering if its possible to find where a constant is being redefined was initially defined? Turning on display_errors to E_ALL will just throw Notice where a constant was being redefined, but it did not say which file/function it was initially defined.
Regards,
The file/function and line number mentioned in the Notice message is where the constant is defined for the second time.
( although I can understand that one can could interpret this message differently.)
Notice: Constant SES_REGION already defined in <php-file> on line 7
To be clear: the notice does NOT say where the constant was originally defined.
Is says where it is redefined.

PHP disable error from specific file?

I am getting hundreds of from ANSI.php. Here is an example:
/usr/share/pear/File/ANSI.php on line 553 Notice: Undefined offset: 75 in
/usr/share/pear/File/ANSI.php on line 555 Notice: Undefined offset: 76 in
/usr/share/pear/File/ANSI.php on line 553 Notice: Undefined offset: 76 in
/usr/share/pear/File/ANSI.php on line 555 Notice: Undefined offset: 77 in
/usr/share/pear/File/ANSI.php on line 555 Notice: Trying to get property of non-object in
/usr/share/pear/File/ANSI.php on line 496 Notice: Trying to get property of non-object in
This is generating from:
$ansi->appendString($ssh->read());
Everything is working. I suspect the old machines I am working with are giving ANSI.php a hard time.
Is there a way i can disable just the error messages from ANSI.PHP and keep the others? Unless someone has a way of fixing the error.
Simplest Solution (Sub-Optimal)
I guess the simplest way to suppress the errors would be to use the error suppression operator #. eg.
#$ansi->appendString($str);
Optimal Solution (Possibly)
There have been two commits to phpseclib since the latest release (1.0.7 and 2.0.6, as of this post) that fixed issues with File/ANSI.php:
https://github.com/phpseclib/phpseclib/commit/5c792f6bc1fa8a5d26b43fb8200191c073637e15
https://github.com/phpseclib/phpseclib/commit/84d1628cb7734134b1ba80545b38985025942b79
More info:
https://github.com/phpseclib/phpseclib/issues/1161
https://github.com/phpseclib/phpseclib/issues/1150
Kinda makes me wonder if one of those might fix the issue for you.
Fallback to Optimal Solution
If the previously mentioned "optimal solution" doesn't fix the issue for you then it would be nice to fix the problem at the source. What'd help me do that would be a copy of the data you got before you passed it to $ansi->appendString(). To make it so the characters don't get garbled because they're extended ASCII maybe hex encode it. eg. echo bin2hex($ssh->read()); or something.

PHP Errors Cond and 1 more

currently Developing a website for my local isp, anyway they want a speed test, soo oolka net gauge is out of the question so i chose http://www.v-speed.eu I quite like their UI but anyway i get these errors on the main page
Notice: Undefined index: link in C:\xampp\htdocs\speed\index.php on
line 48
Notice: Undefined variable: cond in
C:\xampp\htdocs\speed_class\class.core.php on line 961
Notice: Undefined variable: cond in
C:\xampp\htdocs\speed_class\class.core.php on line 990
Notice: Undefined offset: 5 in
C:\xampp\htdocs\speed_class\class.core.php on line 1022
Couldn't figure it out
http://pastebin.com/s1tMEMaf
Just want to fix this
$sql = "
SELECT
COUNT(id) AS count
FROM
boxes
WHERE
1 ".$cond."
ORDER BY
order ASC
";
well You are using a variable ($cond) in a method where it is not defined yet.
How are you suppose to append something to something that is not there. (starting on line 948 )
You might want to start with $cond = "";
or
if($text) $cond = " AND (`name` LIKE :text)";
Your undefined offset on 1022 means that your probably get NULL on a key that you are trying to get that does not exist.
As Rahul stated, you should read the error messages properly. The errors you mention tell a lot already and should give enough information for you to debug it.

variable define error in PHP picture uploading [duplicate]

This question already has answers here:
What does the PHP error message "Notice: Use of undefined constant" mean?
(2 answers)
Closed 8 years ago.
I'm only a beginner with PHP and server side programming so excuse me for this question about variables. I was reading a tutorial about uploading a photo.
(tutorial on plus2net)
and like described in the tutorial i directly copied and pasted the code after understanding it. However the webpage filled with following errors after i inserted PHP in to the HTML.
Notice: Use of undefined constant size - assumed 'size' in C:\Program Files (x86)\XAMPP\htdocs\college_ink\shirtDesign.php on line 44
Notice: Undefined index: file_up in C:\Program Files
(x86)\XAMPP\htdocs\college_ink\shirtDesign.php on line 44
Notice: Use of undefined constant file_up - assumed 'file_up' in
C:\Program Files (x86)\XAMPP\htdocs\college_ink\shirtDesign.php on
line 45
Notice: Use of undefined constant name - assumed 'name' in C:\Program
Files (x86)\XAMPP\htdocs\college_ink\shirtDesign.php on line 45
Notice: Undefined index: file_up in C:\Program Files
(x86)\XAMPP\htdocs\college_ink\shirtDesign.php on line 45
Notice: Use of undefined constant file_up - assumed 'file_up' in
C:\Program Files (x86)\XAMPP\htdocs\college_ink\shirtDesign.php on
line 47
Notice: Use of undefined constant size - assumed 'size' in C:\Program
Files (x86)\XAMPP\htdocs\college_ink\shirtDesign.php on line 47
Notice: Undefined index: file_up in C:\Program Files
(x86)\XAMPP\htdocs\college_ink\shirtDesign.php on line 47
Notice: Use of undefined constant file_up - assumed 'file_up' in
C:\Program Files (x86)\XAMPP\htdocs\college_ink\shirtDesign.php on
line 51
This is the PHP Code:
<?Php
$file_upload="true";
$file_up_size=$_FILES['file_up'][size];
echo $_FILES[file_up][name];
if ($_FILES[file_up][size]>500000){
$msg=$msg."Uploaded file size more than 500KB<BR>";
$file_upload="false";}
if (!($_FILES[file_up][type] =="image/jpeg" OR $_FILES[file_up][type] =="image/png")){
$msg=$msg."Your uploaded file must be of JPG or PNG.<BR>";
$file_upload="false";}
$file_name=$_FILES[file_up][name];
$add="upload/$file_name"; //the path with the file name
if($file_upload=="true"){
if(move_uploaded_file ($_FILES[file_up][tmp_name], $add)){
//do your coding here to give a thanks message
}
else{
echo "Failed to upload file.";}
}
else{
echo $msg;
}
?>
I've corrected the variable error but I'm getting this error now instead
Notice: Undefined index: file_up in C:\Program Files
(x86)\XAMPP\htdocs\college_ink\shirtDesign.php on line 44
Please guide me through this. :)
Where you have
$file_up_size=$_FILES['file_up'][size];
size is being interpreted as a constant due to the lack of a dollar sign.
What you want is
$file_up_size=$_FILES['file_up']['size'];
The problem is that you are relying on bare strings being interpreted as such. Normally, in PHP code, this is considered a constant:
echo FOO;
If you don't define that constant first, like this:
define('FOO', 'foo');
You will encounter this error and PHP will interpret it as a bare string and echo FOO. This is a bad choice. I think what you mean to do is use actual strings (rather than undefined constants) as your array indices:
if ($_FILES['file_up']['size']>500000){
// etc..
Which is what is recommended.
Note: Bare strings are covered in the manual entry for Arrays, specifically underneath the section Arrays do's and don'ts (the manual says don't do this).
This is wrong, but it works. The reason is that this code has an
undefined constant (bar) rather than a string ('bar' - notice the
quotes). PHP may in future define constants which, unfortunately for
such code, have the same name. It works because PHP automatically
converts a bare string (an unquoted string which does not correspond
to any known symbol) into a string which contains the bare string. For
instance, if there is no defined constant named bar, then PHP will
substitute in the string 'bar' and use that.

Drupal error after creating new theme ,Undefined variable: hide_site_name and other similar error

I am new to drupal theme . I have created a direcory mytheme and added mytheme.info to it and copied other files from drupal's default theme directory . Now after editing the page.tpl.php, drupal is showing the errors below .
Notice: Undefined variable: hide_site_name in include() (line 99 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined variable: hide_site_name in include() (line 109 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: featured in include() (line 168 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: highlighted in include() (line 187 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: sidebar_second in include() (line 212 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: triptych_first in include() (line 220 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: triptych_middle in include() (line 220 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: triptych_last in include() (line 220 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: footer_firstcolumn in include() (line 230 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: footer_secondcolumn in include() (line 230 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: footer_thirdcolumn in include() (line 230 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
Notice: Undefined index: footer_fourthcolumn in include() (line 230 of C:\wamp\www\dtest\sites\all\themes\mytheme\bartik\templates\page.tpl.php).
After searching on google, I have found that clearing cache will solve the problem . But even after clearing my cache,it remains the same !
Generally these errors occurred when you call a region in your page.tpl.php file that doesn't exist in the theme's .info file.
In your page.tpl.php:
$page['footer_firstcolumn'];
In your theme's .info:
regions[footer_firstcolumn] = Footer first column
After rechecking all regions, don't forget to flush the cache.
If you want to create a fresh theme best practice is to use something like Zen. It's blank and fully customizable.
As long as you follow the prescribed instructions, you will avoid nasty errors like the ones you have above
i had almost the same problem of messages saying "Notice: undefined index: myIndex in include() (line n in some/path/myPage.tpl.php)" whe i was coding my custom sub-template
I kind of solved the problem using php's function isset() for every line told in the Notice message.
For example in your line 99 i would use:
if(isset(hide_site_name)){
//use hide_site_name in the normal way
}
or in your line 168
if(isset( some_var[featured] )){
//use "featured" index in the normal way
}
hope this helps someone as this helped me after a long time searching for a solution.
i never found the cause of this behavior btw.
sorry for bad grammar, if there's any.
I had the same problem after creating a sub theme and I followed the answer by Meiker and it worked great about including isset. But as I do not have a lot of experience with programing I ran into a snag with line 220 and multiple triptych in the same line.
Notice: Undefined index: triptych_first in include() (line 220 of
C:\wamp\www\dtest\sites\all\themes
So I added isset like this:
if(isset($page['triptych_first']) || (isset($page['triptych_middle']) || (isset($page['triptych_last'])))) :
and did the same for similar error lines and now I do not have any more errors appearing.
I hope this helps others who are programming challenged.

Categories