473,248 Members | 1,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,248 software developers and data experts.

if statement

I am trying to remember how you write an if statement to check if any value
has been entered. For example seeing if a username has been entered in form.
I have seen the following:

if ($username == '')
{
print ("You've pressed submit without entering your username");
}

However is there another method which uses an exclamation mark? I am sure I
have seen something for where $username has no value but I can't think what
it was.

Cheers

Phil


Nov 6 '06 #1
7 1220
ph********@f-in-stupid.co.uk says...
I am trying to remember how you write an if statement to check if any value
has been entered. For example seeing if a username has been entered in form.
I have seen the following:

if ($username == '')
{
print ("You've pressed submit without entering your username");
}

However is there another method which uses an exclamation mark? I am sure I
have seen something for where $username has no value but I can't think what
it was.
isSet ??

if (!isSet($username)) { // do this if $username is not set

GM

Nov 6 '06 #2
>I am trying to remember how you write an if statement to check if any value
>has been entered. For example seeing if a username has been entered in form.
The variable $_GET['username'] or $_POST['username'] is where the
input from a form element appears in a modern version of PHP, not $username.
>I have seen the following:

if ($username == '')
{
print ("You've pressed submit without entering your username");
}

However is there another method which uses an exclamation mark? I am sure I
have seen something for where $username has no value but I can't think what
it was.
You can use isset($_GET['username']) to determine if the value was given
at all.
Nov 6 '06 #3
You can use isset($_GET['username']) to determine if the value was given
at all.
Yep. That was it. Thanks.

Cheers

Phil
Nov 6 '06 #4
isSet ??
>
if (!isSet($username)) { // do this if $username is not set

GM
Yep. That was it. Thanks.

Cheers

Phil
Nov 6 '06 #5
"Geoff Muldoon" <ge***********@trap.gmail.comwrote in message
news:MP************************@news.readfreenews. net...
ph********@f-in-stupid.co.uk says...
>I am trying to remember how you write an if statement to check if any
value
has been entered. For example seeing if a username has been entered in
form.
I have seen the following:

if ($username == '')
{
print ("You've pressed submit without entering your username");
}

However is there another method which uses an exclamation mark? I am sure
I
have seen something for where $username has no value but I can't think
what
it was.

isSet ??

if (!isSet($username)) { // do this if $username is not set

If this is form validation, then isset won't do any good. The form field
will be set, but it still may be empty. Better test that strlen() is greater
than zero, or use empty(). And Of course, there's always the $username vs.
$_POST['username'] issue. Seems like someone is using register_globals, for
shame...

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Nov 6 '06 #6
If this is form validation, then isset won't do any good. The form field
will be set, but it still may be empty. Better test that strlen() is
greater than zero, or use empty(). And Of course, there's always the
$username vs. $_POST['username'] issue. Seems like someone is using
register_globals, for shame...
Not using register_globals but wish I had noticed your post earlier
regarding the form validation issue. I assumed isset meant that it checked
to see if it is actually set to something (had a value), not that it merely
existed. Oh well.. it's all good learning.

Cheers

Phil
Nov 7 '06 #7
>Not using register_globals but wish I had noticed your post earlier
>regarding the form validation issue. I assumed isset meant that it checked
to see if it is actually set to something (had a value), not that it merely
existed. Oh well.. it's all good learning.
A zero-length string is a real value. Whether or not you consider
it to be an error, an unspecified value, or an explicitly specified
value (the value when displaying the form might NOT be an empty
string, it might be 'No Middle Initial' or the original value from
the database record you're editing) depends on the variable,
what it means, and the application.
Nov 7 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: Fábio Mendes | last post by:
I'm sorry if it's an replicate. Either my e-mail program is messing with things or the python-list sent my msg to /dev/null. I couldn't find anything related in previous PEP's, so here it goes a...
15
by: Nerox | last post by:
Hi, If i write: #include <stdio.h> int foo(int); int main(void){ int a = 3; foo(a); }
13
by: eman1000 | last post by:
I was recently looking at the prototype library (http://prototype.conio.net/) and I noticed the author used the following syntax: Object.extend(MyObj.prototype, { my_meth1: function(){},...
37
by: Steven Bethard | last post by:
The PEP below should be mostly self explanatory. I'll try to keep the most updated versions available at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
18
by: Steven Bethard | last post by:
I've updated the PEP based on a number of comments on comp.lang.python. The most updated versions are still at: http://ucsu.colorado.edu/~bethard/py/pep_create_statement.txt...
28
by: Steven Bethard | last post by:
Ok, I finally have a PEP number. Here's the most updated version of the "make" statement PEP. I'll be posting it shortly to python-dev. Thanks again for the previous discussion and suggestions!...
7
by: Steven Bethard | last post by:
I've updated PEP 359 with a bunch of the recent suggestions. The patch is available at: http://bugs.python.org/1472459 and I've pasted the full text below. I've tried to be more explicit about...
19
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without...
18
by: dspfun | last post by:
Hi! The words "expression" and "statement" are often used in C99 and C- textbooks, however, I am not sure of the clear defintion of these words with respect to C. Can somebody provide a sharp...
23
by: florian.loitsch | last post by:
According to the spec Section 14 the production SourceElements:SourceElements SourceElement is evaluated as follows: 1. Evaluate SourceElements. 2. If Result(1) is an abrupt completion, return...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.