views:

193

answers:

2

Hi,

Seem to have a unique problem. I'm doing form validation using a php script. I initially wrote this code in 2007. All of a sudden it stopped working, and I've been trying to figure out why.

Here's the code:

<?php
$error_msg = '';

// Only Validate Form when it is submitted
if (isset($formSubmit)) {
   if (!isset($_SESSION["First_Name"])) {
     $get_mbr_id = urlencode ($_POST["GetMbrID"]);
     $_SESSION["MemberID"] = $get_mbr_id;
     }


if (!headers_sent()) {
 header ("Location: mywebsite.com");
 exit (0);
         }
}

if (isset($formExit)) {
 if (!headers_sent()) {
  header ('Location: mywebsiteexit.com');
                  exit (0);
                }
}
?>
<html>
<head>
</head>
<body>
<form name="select_action" method="POST" action="select_action">
<br>
<center>
<input type="submit" name="formSubmit" value="Next">
<input type="reset" name="fieldReset" value="Reset">
<input type="submit" name="formExit" value="Cancel">
</center>
</form>
</body>
</html>

The problem I'm having is this: If the html form code is present, then the header redirect doesn't work. However, if I remove the html form code, change the if(isset(formSubmit)) statement to if(!isset(formSubmit)), then the header redirect will work.

I can't figure what is happening with the form code that causes the header() redirect not to happen.

Any help would be appreciated!

+3  A: 

You have to check for posts data in the $_POST superglobal. Register_globals has turned off.

if (isset($_POST['formSubmit'])) {
//etc.
erenon
I suspect you're right.
zneak
Suggestion: leave it off.Change the code.
LeguRi
If you have updated your PHP, then this is most likely what is wrong. In old versions of PHP you could use $formSubmit to access variables in the post, but due to security reasons this was changed. You can still enable it in the php.ini file, but it is depreciated, and in future versions that won't be possible.
Marius
That was exactly the problem. Register_globals has turned off. Changed the code to the superglobal and works fine. Thanks folks!Really appreciate it! This was driving me crazy!
StumpClassic
A: 
Roland
I am 100% sure there isn't a blank line at the top. I've read through numerous articles about the possibility of headers being sent, but that's not the case here.
StumpClassic