I'm really confused with something I never had any problems with
before... I have a form with a textbox called password. On the second
page that $password is posted to, if I test isset($password) after a
submit, it always evaluates to true, regardless of whether or not
anything was entered into the textbox... echoing the value simply echoes
its contents, which is an empty string. If I test for simply
if($password), however, that does evaluate to false. This doesn't work
in all cases, however, since sometimes it will give an error saying the
variable is not defined (cases in which I've always used isset to test).
I read up on isset() on php.net, and it says that it will return false
if a variable has been set to null... is that not the case here? If
anyone could tell me exactly what type of situation calls for each of
these two methods I would really appreciate it, thanks in advance.
Marcus 3 6546
"Marcus" <Ju********@aol.com> wrote in message
news:3F**************@aol.com... I'm really confused with something I never had any problems with before... I have a form with a textbox called password. On the second page that $password is posted to, if I test isset($password) after a submit, it always evaluates to true, regardless of whether or not anything was entered into the textbox... echoing the value simply echoes its contents, which is an empty string. If I test for simply if($password), however, that does evaluate to false. This doesn't work in all cases, however, since sometimes it will give an error saying the variable is not defined (cases in which I've always used isset to test). I read up on isset() on php.net, and it says that it will return false if a variable has been set to null... is that not the case here? If anyone could tell me exactly what type of situation calls for each of these two methods I would really appreciate it, thanks in advance.
Marcus
Probably something to do with globals, sound like they are on and variables
are alive longer.
RG
"Marcus" <Ju********@aol.com> wrote in message
news:3F**************@aol.com...
[snip] submit, it always evaluates to true, regardless of whether or not anything was entered into the textbox... echoing the value simply echoes its contents, which is an empty string. If I test for simply if($password), however, that does evaluate to false. This doesn't work
Yes, empty string is considered false by PHP
in all cases, however, since sometimes it will give an error saying the variable is not defined (cases in which I've always used isset to test). I read up on isset() on php.net, and it says that it will return false if a variable has been set to null... is that not the case here? If
No, the variable is not undefined, the empty string is still a value, it is
a string with no characters in it, same way that 0 (zero) is a number, not
an undefined integer.
So,
$password = '';
if ( isset($password) ) print "is set";
if ( $password ) print "is non-empty"; else print "is empty";
will print :
is set
is empty
Cos $password is defined, and it has a value, the empty string.
And cos the string has no characters in it, it is considered false, hence
prints "is empty"
anyone could tell me exactly what type of situation calls for each of these two methods I would really appreciate it, thanks in advance.
Marcus
Thanks,
Mark
---------------------------------------------------------------------------
Windows, Linux and Internet Development Consultant
Email: co*******@scriptsmiths.com
Web: http://www.scriptsmiths.com
---------------------------------------------------------------------------
> page that $password is posted to, if I test isset($password) after a submit, it always evaluates to true, regardless of whether or not anything was entered into the textbox... echoing the value simply echoes its contents, which is an empty string. If I test for simply if($password), however, that does evaluate to false. This doesn't work
Usually what I do when testing things like this is to first check if the
variable exists, and then check its value. This way you don't get the error
if you are trying to test the value of something which doesn't exist, but if
it does exist you are still checking its value as you usually would. ie:
if(isset(x))
{
if(x!=0 && x!=NULL && x!= '')
{
<password is set - test password value>
}
else <blank password>
}
else <no password>
David This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: newbie_mw |
last post by:
Hi, I need urgent help with a novice problem. I would appreciate any
advice, suggestions... Thanks a lot in advance! Here it is:
I created a sign-up sheet (reg.html) where people fill in their...
|
by: newbie_mw |
last post by:
Hi Ian,
Thanks for help! The columns and variables are exactly matched so it
shouldn't be the problem. Actually the original html and php files are
pretty long. But I
guess a more detailed...
|
by: dalsoth |
last post by:
Hi Guys
I have created a website and to makes things easier i decided to use dreamweaver to do the secure login section and access levels for the pages.
When testing locally on wamp my website...
|
by: wouter |
last post by:
hey hi.....
I wanna make a switch wich does this:
if pagid is set do A,
if catid is set do B,
if projectid is set do C,
else do D.
So i was thinking something like this:
|
by: bb nicole |
last post by:
BElow is my php code for candidate search, it have 4 criteria which is academic background, functional experience, preferred location and languages ability. but it show yhe blanks page..
Emm, is it...
|
by: Event Horizon |
last post by:
Hi,
I'm trying to add an simple upload applet to shopping cart script. My new
applet form sends all needed post fields ( quantity, product, etc... )
but the "file" post field is hardcoded in...
|
by: arundelo |
last post by:
Is there a way to tell whether accessing a variable will
result in an "Undefined variable" E_NOTICE? isset() almost
does this, but it also returns false if a variable is set to
null:
...
|
by: chumlyumly |
last post by:
Hello -
Please help! I'm creating search pages using Dreamweaver 8, PHP, and MySQL database with Mac OS X. I think my code is good, but when I run my query, I come up with no data, even though...
|
by: SoulIntruder |
last post by:
Hello folks.
I have a beginners question.
I have such script:
<?php
$User = $_POST;
$Password = $_POST;
$Database = $_POST;
|
by: rhodarose |
last post by:
Good day!
I created a webpages and i have a login page consist of Username and Department. And i encountered problem in adding event in my calendar.
This is the flow of my webpage:
First I...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |