Jump to content

Problems with isset() and is_null() on testing server


BigMonkey

Recommended Posts

Hello, you freaks!

 

In the following code--which works on the hosted production site (sometimes), by the way--does not seem to work on the test server.  In this case, the test server is my humble laptop running Apache 2.2.4 and PHP 5, the latest stable release as of about a week ago.

 

This must be an error common to newbies like me, so I'm counting on your collective experience to help with my profound information deficit.

 

The thought here is that the form appears only if the Submit button has not be click; that is, it is not 'set'.  However, once the Submit button is clicked, the variable $submit is set and the form disappears, revealing only the message stating the obvious.  A very useful page, you see!

 

The name of the page is 'test.php' and as you see from the form action, it calls itself.

 

<?php

if (isset($submit))
{
?>

<form action="test.php" method="post">
<p>
First Name: <input name="firstname" type="text"><br />
Last Name: <input name="lastname" type="text">
<input name="submit" type="submit" value="Send">
</p>
</form>

<?php
}
else
{
	echo "You Hit SUBMIT!";  // You mother should be proud!
}
?>

 

Like I said before, it works on the production site, but not on my test server.  I will add that the PHP engine appears to be working, as it will handle other PHP code just fine.

 

Also, when I use is_null() in place of isset(), I seem to have fewer issues on the production server, but it still doesn't work on the test server.

 

Thanks,

 

Robert Nicholas

Link to comment
Share on other sites

try that ok.

<?php

if (isset($_POST['submit']))
{
?>

<form action="test.php" method="post">
<p>
First Name: <input name="firstname" type="text"><br />
Last Name: <input name="lastname" type="text">
<input name="submit" type="submit" value="Send">
</p>
</form>

<?php
}
else
{
	echo "You Hit SUBMIT!";  // You mother should be proud!
}
?>

Link to comment
Share on other sites

Your code seem to be relying on a setting called register_globals to be enabled in order for the code to work correctly. This setting has been disabled by default as it can cause security exploits within your code. When register_globals is disabled you cannot use $(form name here) eg $submit

 

Instead you have use a superglobal array for the type of data you are retrieving. In your case you will want to use the $_POST array variable to fetch post'd data. To get the submit button you'll want to use $_POST['submit'] variable. Here is your new code:

<?php

if (isset($_POST['submit']))
{
?>

<form action="test.php" method="post">
<p>
First Name: <input name="firstname" type="text"><br />
Last Name: <input name="lastname" type="text">
<input name="submit" type="submit" value="Send">
</p>
</form>

<?php
}
else
{
	echo "You Hit SUBMIT!";  // You mother should be proud!
}
?>

 

Also if your production server is running PHP version greater than 4.2.x then you should be able to use the newer superglobal variables when you upgrade your scripts. I would advise you to not reply on register globals when coding scripts and to stick to using superglobals instead.

Link to comment
Share on other sites

Perfect.

 

I've tried turning on the register_globals and turning the register_globals back off in order to test the $_POST superglobal thingy, and both worked wonderfully.

 

I read in the .ini file (sorry, laptop's a Windows gadget) the I should write code that avoids the necessity of turning register_globals ON, and in your respective replies you've mentioned security issues.  So I've decided on using the safer of the two methods.

 

Now, a side issue involves the use of isset() as it relates to the use of is_null().  In this case, is_null() appears to work more consistently than isset(), which, when employed, causes the new page many times to load is if the SUBMIT button were already clicked--as if the $submit / $_POST['submit'] were already set.

 

Since, to newbies such as myself, the PHP Manual can become inscrutable very quickly, I'm rather counting on some additional feedback here.

 

Thanks is advance.

 

Link to comment
Share on other sites

wildteen88,

 

As terse and sparse as your reply is, it is nevertheless quite elucidating.

 

So, regarding your moniker, were you a wild teen in '88 or are you now a wild teen BORN in '88?

 

If the latter, you may find your moniker will not scale beyond next year.

 

Unless, of course, you're 88 and you still feel like a wild teen in which case your moniker will be fine, but your body may not scale beyond next year.

 

:)

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.