Jump to content


Photo

PHP Class Problem


  • Please log in to reply
5 replies to this topic

#1 Eugene

Eugene
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 04 July 2006 - 10:10 PM

*.class.php file
<?
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";
				}
			}
}
?> 
function.inc.php file
<?PHP
include("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();
}

		
?>

When the form is submitted, and i left the field blank for testing purposed and for some reasons it always echoes no.

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 July 2006 - 10:18 PM

For one, you cannot have a method and a property of the same name within the same class.

#3 Eugene

Eugene
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 04 July 2006 - 10:19 PM

For one, you cannot have a method and a property of the same name within the same class.

What's that?

#4 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 04 July 2006 - 10:25 PM

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.

#5 Eugene

Eugene
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 04 July 2006 - 10:31 PM

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.

<?PHP
class 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";
				}
			}
}
?>

Changed it all, it still outputs "no".

#6 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 05 July 2006 - 07:43 AM

are you doing both actions this time
you first have to give

$this->username a value before you run the function


Like so
//Username
$input = new check_input;
$input->username = $_POST['username'];
$input->username();

//Password
$input->password = $_POST['password'];
$input->password();

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users