Jump to content

Archived

This topic is now archived and is closed to further replies.

Eugene

PHP Class Problem

Recommended Posts

*.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]
<?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();
}


?>
[/code]

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

Share this post


Link to post
Share on other sites
For one, you cannot have a method and a property of the same name within the same class.

Share this post


Link to post
Share on other sites
[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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[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]<?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";
}
}
}
?> [/code]

Changed it all, it still outputs "no".

Share this post


Link to post
Share on other sites
are you doing both actions this time
you first have to give

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


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

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.