Jump to content

new/same problem


Eugene

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]
Link to comment
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.
Link to comment
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.
Link to comment
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.
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.