473,289 Members | 1,952 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,289 software developers and data experts.

Help needed with is_null

Would someone be so kind as to tell me what is wrong with this code?

(1) This code block indicates the session variable nomex is null.
if (is_null($_SESSION['nomex'])){
echo " is null.";
}
else {
echo " is not null.";
}

(2) However on the same page this code block always adds 100 to the
price.
if ($_SESSION['nomex'] != "^^no^^"){
if (!is_null($_SESSION['nomex'])){
// NOMEX Lining
$new_price = $new_price + 100;
}
}
echo "$".$new_price;

Thank you very much!!

Aug 4 '07 #1
7 1448
Big Moxy wrote:
Would someone be so kind as to tell me what is wrong with this code?

(1) This code block indicates the session variable nomex is null.
if (is_null($_SESSION['nomex'])){
echo " is null.";
}
else {
echo " is not null.";
}

(2) However on the same page this code block always adds 100 to the
price.
if ($_SESSION['nomex'] != "^^no^^"){
If it wasn't defined before, it is now.
if (!is_null($_SESSION['nomex'])){
So this will never be true.
// NOMEX Lining
$new_price = $new_price + 100;
}
}
echo "$".$new_price;

Thank you very much!!
BTW - if you're checking to see if something is set, isset() is better.
But either way, check BEFORE you reference it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 4 '07 #2
On Aug 3, 8:22 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
Big Moxy wrote:
Would someone be so kind as to tell me what is wrong with this code?
(1) This code block indicates the session variable nomex is null.
if (is_null($_SESSION['nomex'])){
echo " is null.";
}
else {
echo " is not null.";
}
(2) However on the same page this code block always adds 100 to the
price.
if ($_SESSION['nomex'] != "^^no^^"){

If it wasn't defined before, it is now.
if (!is_null($_SESSION['nomex'])){

So this will never be true.
// NOMEX Lining
$new_price = $new_price + 100;
}
}
echo "$".$new_price;
Thank you very much!!

BTW - if you're checking to see if something is set, isset() is better.
But either way, check BEFORE you reference it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================
I think I understand your response however I am a PHP newbie so could
you please redo my code with isset()?

Thank you!

Aug 4 '07 #3
Jerry Stuckle wrote:
Big Moxy wrote:
>Would someone be so kind as to tell me what is wrong with this code?

(1) This code block indicates the session variable nomex is null.
if (is_null($_SESSION['nomex'])){
echo " is null.";
}
else {
echo " is not null.";
}

(2) However on the same page this code block always adds 100 to the
price.
if ($_SESSION['nomex'] != "^^no^^"){

If it wasn't defined before, it is now.
Maybe, but if referencing an undefined variable sets it, it will be set to NULL.

if ($_SESSION['nothing']){}
var_dump($_SESSION['nothing']);

output: NULL
>
> if (!is_null($_SESSION['nomex'])){

So this will never be true.
What do you mean it will never be true. It will be true if that variable
had a non-null value to begin with.
>
BTW - if you're checking to see if something is set, isset() is better.
But either way, check BEFORE you reference it.
Either way in this case.
Aug 4 '07 #4
Big Moxy wrote:
Would someone be so kind as to tell me what is wrong with this code?
Nothing that I can see...
>
(1) This code block indicates the session variable nomex is null.
if (is_null($_SESSION['nomex'])){
echo " is null.";
}
else {
echo " is not null.";
}

(2) However on the same page this code block always adds 100 to the
price.
That can't be true. If the above code said it was NULL, then the
second IF block below can't be executing. Are you sure that there
isn't something in between these two blocks of code. Is this even
your "real" code, or just a quick rewrite.
if ($_SESSION['nomex'] != "^^no^^"){
if (!is_null($_SESSION['nomex'])){
// NOMEX Lining
$new_price = $new_price + 100;
}
}
echo "$".$new_price;
I execute this code:
-------
$new_price = 49;
if (is_null($_SESSION['nomex'])){
echo " is null.";
}
else {
echo " is not null.";
}
if ($_SESSION['nomex'] != "^^no^^"){
if (!is_null($_SESSION['nomex'])){
// NOMEX Lining
$new_price = $new_price + 100;
}
}
echo "$".$new_price;
-------

Output is:

is null.$49

Aug 4 '07 #5
Matt Madrid wrote:
Jerry Stuckle wrote:
>Big Moxy wrote:
>>Would someone be so kind as to tell me what is wrong with this code?

(1) This code block indicates the session variable nomex is null.
if (is_null($_SESSION['nomex'])){
echo " is null.";
}
else {
echo " is not null.";
}

(2) However on the same page this code block always adds 100 to the
price.
if ($_SESSION['nomex'] != "^^no^^"){

If it wasn't defined before, it is now.

Maybe, but if referencing an undefined variable sets it, it will be set
to NULL.

if ($_SESSION['nothing']){}
var_dump($_SESSION['nothing']);

output: NULL
>>
>> if (!is_null($_SESSION['nomex'])){

So this will never be true.

What do you mean it will never be true. It will be true if that variable
had a non-null value to begin with.
You're correct - it will be true in this case.
>
>>
BTW - if you're checking to see if something is set, isset() is
better. But either way, check BEFORE you reference it.

Either way in this case.
Not at all. There is a definite difference between isset() and isnull().

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 4 '07 #6
Big Moxy wrote:
if ($_SESSION['nomex'] != "^^no^^"){
if (!is_null($_SESSION['nomex'])){
// NOMEX Lining
$new_price = $new_price + 100;
}
}
echo "$".$new_price;
if (isset($_SESSION['nomex']) && $_SESSION['nomex']!='^^no^^')
$new_price += 100;

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 44 days, 15:52.]

Command Line Interfaces, Again
http://tobyinkster.co.uk/blog/2007/0...nd-line-again/
Aug 4 '07 #7
Big Moxy wrote:
On Aug 3, 8:22 pm, Jerry Stuckle <jstuck...@attglobal.netwrote:
>Big Moxy wrote:
>>Would someone be so kind as to tell me what is wrong with this code?
(1) This code block indicates the session variable nomex is null.
if (is_null($_SESSION['nomex'])){
echo " is null.";
}
else {
echo " is not null.";
}
(2) However on the same page this code block always adds 100 to the
price.
if ($_SESSION['nomex'] != "^^no^^"){
If it wasn't defined before, it is now.
>> if (!is_null($_SESSION['nomex'])){
So this will never be true.
>> // NOMEX Lining
$new_price = $new_price + 100;
}
}
echo "$".$new_price;
Thank you very much!!
BTW - if you're checking to see if something is set, isset() is better.
But either way, check BEFORE you reference it.

I think I understand your response however I am a PHP newbie so could
you please redo my code with isset()?

Thank you!
It's not hard - just use isset() before you do anything else with it:

Note the difference between isset() and is_null(). isset() is a language
construct, not a function call (despite its looks). isset() doesn't
change anything.

is_null() is a function call, and when you pass a variable which doesn't
exist, it is initialized and set to null.

Now - I shouldn't have been answering at midnight last night :-). But
the code you should use would be more like:

if (isset($_SESSION['nomex'])){
echo " is initialized.";
}
else {
echo " is not initialized.";
}

....

if (isset($_SESSION['nomex'])) {
if (!is_null($_SESSION['nomex']) {
if ($_SESSION['nomex'] != "^^no^^"){
// NOMEX Lining
$new_price = $new_price + 100;
}
}
}
echo "$".$new_price;

And ensure you're not setting $_SESSION['nomex'] in between your first
and second tests.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Aug 4 '07 #8

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

Similar topics

4
by: Peter Croft | last post by:
I am a newcomer to php; I recently loaded a binary copy (5.0.3) onto my PC running win2k and Apache 2.0.52. It seems to work fine except that it is very slow running the function is_null e.g. the...
28
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical...
7
by: Tina | last post by:
I have an asp project that has 144 aspx/ascx pages, most with large code-behind files. Recently my dev box has been straining and taking long times to reneder the pages in the dev environment. ...
10
by: Mae Lim | last post by:
Dear all, I'm new to C# WebServices. I compile the WebService project it return no errors "Build: 1 succeeded, 0 failed, 0 skipped". Basically I have 2 WebMethod, when I try to invoke the...
3
by: Kitana907 | last post by:
Hi- I'm attempting to write a module that uses and updates info from two tables and does the following: Opens the recordset of a table called "tblstoreinv" If the Needed Field in the...
0
by: josh.23.french | last post by:
Here's the code i have: $db = array(); //main array $db = array(); //table `main` $db = array('id'=>0, 'username'=>'joshfrench','userpass'=>'password','userlevel'=>'admin'); //row $db =...
9
by: smartbei | last post by:
Hello, I am a newbie with python, though I am having a lot of fun using it. Here is one of the excersizes I am trying to complete: the program is supposed to find the coin combination so that with...
2
by: rookiejavadude | last post by:
I'm have most of my java script done but can not figure out how to add a few buttons. I need to add a delete and add buttong to my existing java program. Not sure were to add it on how. Can anyone...
0
by: Doan Noahlot | last post by:
Is there a meaningful/usefull difference between $x == null and is_null($x)?
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: 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...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

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.