Jump to content


Photo

new/same problem


  • Please log in to reply
4 replies to this topic

#1 Eugene

Eugene
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 05 July 2006 - 12:00 AM

I decided to do something simple. I left the input blank, it returned "it's empty".
I typed something in, it return "it's empty". Big problem, no idea hot to solve it.

<?
class MyClass{
    var $username;
    
    // use a function without variables 
   function username_r() {
	if(isset($this->username)) {
		echo "it's empty";
		}
	else {
		echo "it's not empty";
	}
	}
}
if($_POST['submit']) {
$myclass = new MyClass;
$myclass->username = $_POST['username'];

$myclass->username_r();
}
echo "<form method=\"post\">
<input type=\"text\" name=\"username\">
<input type=\"submit\" name=\"submit\">
</form>";
?>


#2 dwees

dwees
  • Members
  • PipPipPip
  • Advanced Member
  • 47 posts
  • LocationUnited Kingdom

Posted 05 July 2006 - 12:05 AM

I think the
if($_POST['submit'])

should be:

if($_POST['username'])

Does that work?

#3 Eugene

Eugene
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 05 July 2006 - 12:16 AM

I think the

if($_POST['submit'])

should be:

if($_POST['username'])

Does that work?

If I enter something into the value. It say's empty. If i don't enter anything. Nothing happens.

#4 trq

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

Posted 05 July 2006 - 12:16 AM

Because $this->username is defined in your class. Empty or not, isset($this->username) will always return true. Try this...

<?php
class MyClass {
  var $username;
  function username_r() {
    if (empty($this->username)) {
      echo "is empty";
    } else {
      echo "is not empty";
    }
  }
}
?>
Besides which... you have your its empty and its not empty around the wrong way.

#5 Eugene

Eugene
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 05 July 2006 - 12:24 AM

Because $this->username is defined in your class. Empty or not, isset($this->username) will always return true. Try this...

<?php
class MyClass {
  var $username;
  function username_r() {
    if (empty($this->username)) {
      echo "is empty";
    } else {
      echo "is not empty";
    }
  }
}
?>
Besides which... you have your its empty and its not empty around the wrong way.

Works, thanks a lot dude.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users