I'm trying to use this variable <?php echo $text2; ?> PHP: but I'm getting an error: Error Message: Undefined variable: text2 Code (markup): This is the code: class Subpage { static function Build() { if(User::$isLoggedin != TRUE) { redirect('login'); } $details = User::$details; if(isset($_POST['update'])) { if(strlen($_POST['details']) >= 15) { $text2 = 'test'; } elseif(strlen($_POST['details']) <= 15) { $id = User::$id; $details = $_POST['details']; $db_details = DB::safe($details); DB::query("UPDATE top_topsites SET details = '$db_details' WHERE id = '$id' LIMIT 1"); } } Load::view('ucp/details', array('id' => User::$id, 'siteurl' => Config::item('siteurl'), 'details' => $details)); } } PHP: Thanks
$text2 is being defined here: [COLOR=#b1b100]if[/COLOR][COLOR=#009900]([/COLOR][URL="http://www.php.net/strlen"][COLOR=#990000]strlen[/COLOR][/URL][COLOR=#009900]([/COLOR][COLOR=#000088]$_POST[/COLOR][COLOR=#009900][[/COLOR][COLOR=#0000ff]'details'[/COLOR][COLOR=#009900]][/COLOR][COLOR=#009900])[/COLOR] [COLOR=#339933]>=[/COLOR] [COLOR=#cc66cc]15[/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR] [COLOR=#000088]$text2[/COLOR] [COLOR=#339933]=[/COLOR] [COLOR=#0000ff]'test'[/COLOR][COLOR=#339933];[/COLOR] [COLOR=#009900]}[/COLOR] Code (markup): If the condition is false, $text2 never gets defined. Try [COLOR=#b1b100]$text2 = ''; if[/COLOR][COLOR=#009900]([/COLOR][URL="http://www.php.net/strlen"][COLOR=#990000]strlen[/COLOR][/URL][COLOR=#009900]([/COLOR][COLOR=#000088]$_POST[/COLOR][COLOR=#009900][[/COLOR][COLOR=#0000ff]'details'[/COLOR][COLOR=#009900]][/COLOR][COLOR=#009900])[/COLOR] [COLOR=#339933]>=[/COLOR] [COLOR=#cc66cc]15[/COLOR][COLOR=#009900])[/COLOR] [COLOR=#009900]{[/COLOR] [COLOR=#000088]$text2[/COLOR] [COLOR=#339933]=[/COLOR] [COLOR=#0000ff]'test'[/COLOR][COLOR=#339933];[/COLOR] [COLOR=#009900]}[/COLOR] Code (markup):
self::$text2 = ''; if(strlen($_POST['details']) >= 15) { self::$text2 = 'test'; } Code (markup): Then do echo Subpage::$text2; Code (markup):
Fatal error: Access to undeclared static property: Subpage::$text2 in D:\xampp\htdocs\top\templates\v1\pages\ucp\details.php on line 40 Code (markup):
Where is <?php echo $text2; ?> PHP: appearing? It's undefined outside the function it's being defined in. You can declare it public in the class and access it from outside. But what you do depends on where you're trying to use it.
undefined variables shouldn't be reported anyways. that way you can use the isset function if you choose.