BigMonkey Posted June 30, 2007 Share Posted June 30, 2007 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 Quote Link to comment Share on other sites More sharing options...
king arthur Posted June 30, 2007 Share Posted June 30, 2007 It may be something like, the production server has register_globals turned on, and the installation on your laptop doesn't. Check each by running phpInfo(). Quote Link to comment Share on other sites More sharing options...
redarrow Posted June 30, 2007 Share Posted June 30, 2007 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! } ?> Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 30, 2007 Share Posted June 30, 2007 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. Quote Link to comment Share on other sites More sharing options...
BigMonkey Posted June 30, 2007 Author Share Posted June 30, 2007 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. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 30, 2007 Share Posted June 30, 2007 Huh! isset and is_null checks for two completely different things. isset checks for variable existence and is_null checks to see if the variable holds a null value and not the existence. Quote Link to comment Share on other sites More sharing options...
BigMonkey Posted June 30, 2007 Author Share Posted June 30, 2007 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. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted June 30, 2007 Share Posted June 30, 2007 the 88 is my birth year - 1988. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.