Eugene Posted July 5, 2006 Share Posted July 5, 2006 I decided to do something simple. I left the input blank, it returned "it's empty".I typed something in, it return "it's empty". Big problem, no idea hot to solve it.[code=php:0]<?class MyClass{ var $username; // use a function without variables function username_r() { if(isset($this->username)) { echo "it's empty"; } else { echo "it's not empty"; } }}if($_POST['submit']) {$myclass = new MyClass;$myclass->username = $_POST['username'];$myclass->username_r();}echo "<form method=\"post\"><input type=\"text\" name=\"username\"><input type=\"submit\" name=\"submit\"></form>";?>[/code] Link to comment https://forums.phpfreaks.com/topic/13687-newsame-problem/ Share on other sites More sharing options...
dwees Posted July 5, 2006 Share Posted July 5, 2006 I think the [code] if($_POST['submit']) [/code]should be:[code] if($_POST['username']) [/code]Does that work? Link to comment https://forums.phpfreaks.com/topic/13687-newsame-problem/#findComment-53097 Share on other sites More sharing options...
Eugene Posted July 5, 2006 Author Share Posted July 5, 2006 [quote author=dwees link=topic=99461.msg391670#msg391670 date=1152057938]I think the [code] if($_POST['submit']) [/code]should be:[code] if($_POST['username']) [/code]Does that work?[/quote]If I enter something into the value. It say's empty. If i don't enter anything. Nothing happens. Link to comment https://forums.phpfreaks.com/topic/13687-newsame-problem/#findComment-53100 Share on other sites More sharing options...
trq Posted July 5, 2006 Share Posted July 5, 2006 Because $this->username is defined in your class. Empty or not, isset($this->username) will always return true. Try this...[code=php:0]<?phpclass MyClass { var $username; function username_r() { if (empty($this->username)) { echo "is empty"; } else { echo "is not empty"; } }}?>[/code]Besides which... you have your [i]its empty[/i] and [i]its not empty[/i] around the wrong way. Link to comment https://forums.phpfreaks.com/topic/13687-newsame-problem/#findComment-53101 Share on other sites More sharing options...
Eugene Posted July 5, 2006 Author Share Posted July 5, 2006 [quote author=thorpe link=topic=99461.msg391674#msg391674 date=1152058605]Because $this->username is defined in your class. Empty or not, isset($this->username) will always return true. Try this...[code=php:0]<?phpclass MyClass { var $username; function username_r() { if (empty($this->username)) { echo "is empty"; } else { echo "is not empty"; } }}?>[/code]Besides which... you have your [i]its empty[/i] and [i]its not empty[/i] around the wrong way.[/quote]Works, thanks a lot dude. Link to comment https://forums.phpfreaks.com/topic/13687-newsame-problem/#findComment-53104 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.