Eugene Posted July 4, 2006 Share Posted July 4, 2006 *.class.php file[code]<?class check_input { var $ID; var $username; var $password; var $confirm_password; var $email; var $confirm_email; var $joindateshort; var $joindatelong; var $IP; var $sql; function username() { if(isset($this->username) || (strlen($this->username) >= 3)) { echo "yes"; } else { echo "no"; } }}?> [/code]function.inc.php file[code]<?PHPinclude("register.class.php");//Username$input = new check_input;$input->username = $_POST['username'];//Password$input->password = $_POST['password'];//Confirm Password$input->confirm_password = $_POST['password'];//Email $input->email = $_POST['email'];//Confirm Email$input->confirm_email = $_POST['confirm_email'];//RuneScape Name$input->runescape_name = $_POST['runescape_name'];//Join dates$input->joindateshort = date("m/d/y");$input->joindatelong = date("r");//IP Address$input->ip = $_SERVER['REMOTE_ADDR'];if($_POST['submit']) {//Let's start shall we? $check_r = new check_input; $check_r->username();} ?>[/code]When the form is submitted, and i left the field blank for testing purposed and for some reasons it always echoes no. Link to comment https://forums.phpfreaks.com/topic/13676-php-class-problem/ Share on other sites More sharing options...
trq Posted July 4, 2006 Share Posted July 4, 2006 For one, you cannot have a method and a property of the same name within the same class. Link to comment https://forums.phpfreaks.com/topic/13676-php-class-problem/#findComment-53052 Share on other sites More sharing options...
Eugene Posted July 4, 2006 Author Share Posted July 4, 2006 [quote author=thorpe link=topic=99448.msg391622#msg391622 date=1152051504]For one, you cannot have a method and a property of the same name within the same class.[/quote]What's that? Link to comment https://forums.phpfreaks.com/topic/13676-php-class-problem/#findComment-53053 Share on other sites More sharing options...
trq Posted July 4, 2006 Share Posted July 4, 2006 You have defined a var (property) as $username, and you also have defined a function (method) as username.$this->username cannot point to two different things at once. Link to comment https://forums.phpfreaks.com/topic/13676-php-class-problem/#findComment-53055 Share on other sites More sharing options...
Eugene Posted July 4, 2006 Author Share Posted July 4, 2006 [quote author=thorpe link=topic=99448.msg391626#msg391626 date=1152051930]You have defined a var (property) as $username, and you also have defined a function (method) as username.$this->username cannot point to two different things at once.[/quote][code]<?PHPclass check_input { var $username_r; var $password_r; var $confirm_password_r; var $email_r; var $confirm_email_r; var $joindateshort_r; var $joindatelong_r; var $IP_r; var $sql; var $warning = array(); function username() { if(isset($this->username_r) || (strlen($this->username_r) >= 3)) { echo "yes"; } else { echo "no"; } }}?> [/code]Changed it all, it still outputs "no". Link to comment https://forums.phpfreaks.com/topic/13676-php-class-problem/#findComment-53057 Share on other sites More sharing options...
Zane Posted July 5, 2006 Share Posted July 5, 2006 are you doing both actions this timeyou first have to give$this->username a value before you run the functionLike so[code]//Username$input = new check_input;$input->username = $_POST['username'];$input->username();//Password$input->password = $_POST['password'];$input->password();[/code] Link to comment https://forums.phpfreaks.com/topic/13676-php-class-problem/#findComment-53206 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.