PHP Notice: Undefin...
 
Notifications
Clear all

PHP Notice: Undefined variable in languages/en.php

1 Posts
1 Users
0 Reactions
285 Views
Jan_AQ
(@jan_aq)
Posts: 1300
Noble Member
Topic starter
 

From error log:

[21-Aug-2023 20:08:30 UTC] PHP Notice: Undefined variable: allowed_tags in /public_html/fanfiction/languages/en.php on line 26
[21-Aug-2023 20:08:30 UTC] PHP Notice: Undefined variable: recentdays in /public_html/fanfiction/languages/en.php on line 137
[21-Aug-2023 20:08:30 UTC] PHP Notice: Undefined variable: multiplecats in /public_html/fanfiction/languages/en.php on line 249
[21-Aug-2023 20:08:30 UTC] PHP Notice: Undefined variable: minwords in /public_html/fanfiction/languages/en.php on line 266
[21-Aug-2023 20:08:30 UTC] PHP Notice: Undefined variable: maxwords in /public_html/fanfiction/languages/en.php on line 266
[21-Aug-2023 20:08:30 UTC] PHP Notice: Undefined variable: action in /public_html/fanfiction/languages/en.php on line 299
[21-Aug-2023 20:08:30 UTC] PHP Notice: Undefined variable: pwdsetting in /public_html/fanfiction/languages/en.php on line 308
[21-Aug-2023 20:08:30 UTC] PHP Notice: Undefined variable: imagewidth in /public_html/fanfiction/languages/en.php on line 323
[21-Aug-2023 20:08:30 UTC] PHP Notice: Undefined variable: imageheight in /public_html/fanfiction/languages/en.php on line 323

 

From
/languages/en.php

Line 26:

define ("_ALLOWEDTAGS", "<span style=\"font-weight: bold; text-decoration: underline;\">Note:</span> Allowed HTML tags are: ".htmlentities(preg_replace("/></", "> <", $allowed_tags)));
 
Line 137:
 
define ("_RECENTSTORIES", "Stories updated in the last ".$recentdays." days.");
 
Line 249:
 
define ("_MISSINGFIELDS", "Some of the required information is missing.  Please check your input.  Required fields are title, summary, ".($multiplecats ? strtolower(_CATEGORIES.", ") : "")."rating, and story text."); // Modified 11/06/05 - If categories are turned off don't show category as required field. 🙂
 
Line 266:
 
define ("_WORDCOUNTFAILED", "Your story failed to meet the required minimum or maximum word count for story submission on this site.  Each chapter must be".($minwords ? " no less than ".$minwords : "").($maxwords ? ($minwords ? " and" : "")." no more than $maxwords " : "")." words long.");
 
Line 299:
 
define ("_PASSWORDTWICE", "You must enter your new password twice. Please <a href=\"user.php?action=".$action."\">try again</a>.");
 
 
Line 308:
 
define ("_SIGNUPTHANKS", "Thank you for signing up! You will receive ".(!$pwdsetting ? "your temporary password" : "a confirmation")." at the e-mail address you provided.");
 
 
Line 323:
 
define ("_IMAGETOOBIG", "This image is too big. Images may only be $imagewidth wide by $imageheight high. Please <a href=\"user.php?action=manageimages&upload=upload\">try again</a>.");
 

---

 

Notice: Undefined variable

This error means that within your code, there is a variable or constant which is not set. But you may be trying to use that variable.

The error can be avoided by using the isset() function.This function will check whether the variable is set or not.

 

Error Example:

<?php
$name='Stechies';
echo $name;
echo $age;
?>

Output:

STechies
Notice: Undefined variable: age in \testsite.loc\varaible.php on line 4

In the above example, we are displaying value stored in the ‘name’ and ‘age’ variable, but we didn’t set the ‘age’ variable.

 

Here are two ways to deal with such notices.

  1. Resolve such notices.
  2. Ignore such notices.

Fix Notice: Undefined Variable by using isset() Function

This notice occurs when you use any variable in your PHP code, which is not set.

Solutions:

To fix this type of error, you can define the variable as global and use the isset() function to check if the variable is set or not.

Example:

<?php
global $name;
global $age;
$name = 'Stechies';

if(!isset($name)){
$name = 'Variable name is not set';
}
if(!isset($age)){
$age = 'Varaible age is not set';
}
echo 'Name: ' . $name.'<br>';
echo 'Age: ' . $age;
?>

Set Index as blank

<?php
$name = 'Stechies';

// Set Variable as Blank
$name = isset($name) ? $name : '';
$age= isset($age) ? $age: '';

echo 'Name: ' . $name.'<br>';
echo 'Age: ' . $age;
?>

Ignore PHP Notice: Undefined variable

You can ignore this notice by disabling reporting of notice with option error_reporting.

1. Disable Display Notice in php.ini file

Open php.ini file in your favorite editor and search for text “error_reporting” the default value is E_ALL. You can change it to E_ALL & ~E_NOTICE.

By default:

error_reporting = E_ALL

Change it to:

error_reporting = E_ALL & ~E_NOTICE

Now your PHP compiler will show all errors except 'Notice.'

2. Disable Display Notice in PHP Code

If you don’t have access to make changes in the php.ini file, In this case, you need to disable the notice by adding the following code on the top of your PHP page.

<?php error_reporting (E_ALL ^ E_NOTICE); ?>

Now your PHP compiler will show all errors except 'Notice.'

https://www.stechies.com/notice-undefined-variable-in-php/


Whoever said nothing is impossible never tried slamming a revolving door.

url: https://www.potionsandsnitches.org/fanfiction
php: 7.4.33 msql: 5.6.51-community GPL
efic version: 3.5.5 latest patches: yes
bridges: none mods: challenges, tracker, story end, beta, word

 
Posted : 21/08/2023 5:10 pm
Share: