1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Rep Power
    What's the diff between function isset() and empty()? I was totally confused.

    I create a table with mysql as:
    create table user(
    id int not null auto increment,
    name varchar(64) not null,
    age int null,
    description text null,
    primary key(id),

    The description is set to null in case someone don't like to introduce himself/herself.
    The age is set to null in case someone don't want to tell the other his/her age.

    Then I have a form where user put their information and a PHP file to handle these information.
    Assume the new user input only his/her name, then
    isset($name)==true and empty($name)==false
    isset($age)==true and empty($age)==true
    isset($description)==true and empty($description)==true
    I use following scripts to insert the new user's information:
    insert into user(name,age,description) values($name,$age,$des)

    Then I will display the information:
    $qid = mysql_query("select name,age,description from user where id='$the_user_id'");
    $user = mysql_fetch_object($qid);

    then, the following two lines are confused me
    echo "$user->age"; //error: undefind property
    echo "$user->description"; //right

    I will appreciate if some one can help me !

    another question, see following urls:

    What about the variable "$id" in user.php ? I know $id is set and value is 3 according to 1st url.
    It is: isset($id)==true and empty($id)==false

    What about the other two?

    Good Good Study
    Day Day Up

    [This message has been edited by xiaoguiwxd (edited September 18, 2000).]
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Rep Power
    Actually both the functions used for determining wether a variable is set or not.

    if you are using empty() function with a variable,it will check wether it is zero or it not holding a value.. then it will return true.



    echo "it is working fine and it is empty or zero";
    //it checks for 0 or no values and return 'true'...

    second case , if you are using isset() will check again wether the variable is set or not..it is a very regularly using function for checking wether variable is set or not..



    echo "yea,variable is set";

    empty function will return true if it is not having any value..

    isset function will return true if the variable is set..

    see the manual for more details...

    SR -
    www.jobxyz.com-IT Career Portal

    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited September 18, 2000).]

Similar Threads

  1. Can user A read user B's session?
    By Stupid Khor in forum PHP Development
    Replies: 9
    Last Post: May 11th, 2004, 05:19 AM
  2. empty texarea in search field prints ALL entries
    By jackass in forum PHP Development
    Replies: 1
    Last Post: November 19th, 2003, 02:04 PM

IMN logo majestic logo threadwatch logo seochat tools logo