0

How to use the function within the class??

class UserRegister{


public $password = '';


public function escape($val)
{
return mysql_real_escape_string($val);
}

public function setPassword($val)
{
$this->password = $val;
$val = escape($this->password);
$this->password = $val;
}

public function getPassword()
{
echo $this->password;   
}

}

$obj = new UserRegister;
echo $obj->setPassword("dsadsadasdas'das");
echo $obj->getPassword();

But it prompt call to undefined function escape(). How can I apply escape() which is return mysql_real_escape_string() to setPassword? I want to let mysql_real_escape_string filter it before it set to $password.

2
Contributors
2
Replies
14
Views
4 Years
Discussion Span
Last Post by devianleong
0

echo $obj->setPassword("dsadsadasdas'das"); this is wrong. Yo don't return anything, so don't output this. You're setting, not getting. What seems to be the error?

1

Thank you phorce. I got the solution now. I just change from this

public function setPassword($val)
{
$this->password = $val;
$val = escape($this->password);
$this->password = $val;
}

to

public function setPassword($val)
{
$this->password = $this->escape($val);
}

and it's work! .. My output is dsadsadasdas\'das now..

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.