Jump to content

Archived

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

Eugene

new/same problem

Recommended Posts

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.

[code=php:0]
<?
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>";
?>
[/code]

Share this post


Link to post
Share on other sites
I think the [code] if($_POST['submit']) [/code]

should be:

[code] if($_POST['username']) [/code]

Does that work?

Share this post


Link to post
Share on other sites
[quote author=dwees link=topic=99461.msg391670#msg391670 date=1152057938]
I think the [code] if($_POST['submit']) [/code]

should be:

[code] if($_POST['username']) [/code]

Does that work?
[/quote]
If I enter something into the value. It say's empty. If i don't enter anything. Nothing happens.

Share this post


Link to post
Share on other sites
Because $this->username is defined in your class. Empty or not, isset($this->username) will always return true. Try this...

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

Share this post


Link to post
Share on other sites
[quote author=thorpe link=topic=99461.msg391674#msg391674 date=1152058605]
Because $this->username is defined in your class. Empty or not, isset($this->username) will always return true. Try this...

[code=php:0]
<?php
class MyClass {
  var $username;
  function username_r() {
    if (empty($this->username)) {
      echo "is empty";
    } else {
      echo "is not empty";
    }
  }
}
?>
[/code]
Besides which... you have your [i]its empty[/i] and [i]its not empty[/i] around the wrong way.
[/quote]
Works, thanks a lot dude.

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.