Jump to content

PHP Class Problem


Eugene

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.
Link to comment
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".
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.