arbitter Posted May 9, 2010 Share Posted May 9, 2010 if(($_GET['fx'] == 'account') && isset($_POST['changepas'])) { $old_pas = $_POST['old_pas']; $new_pas = $_POST['new_pas']; $new_pas2 = $_POST['new_pas2']; if(empty($old_pas) || empty($new_pas) || empty($new_pas2)) { $_SESSION['message'] = 'You must fill in all the fields.'; header("Location: index.php?fx=account"); } $verbinding = mysql_connect(MYSQL_SERVER, MYSQL_GEBRUIKERSNAAM, MYSQL_WACHTWOORD) or die("Connection failed: " . mysql_error()); mysql_select_db('users'); $result = mysql_query("SELECT * FROM users WHERE email='" . $_SESSION['email'] . "' AND nick='" . $_SESSION['nick'] . "'"); $row = mysql_fetch_array($result); if(empty($row)) { $_SESSION['message'] = 'There is a problem with the server'; header("Location: index.php?fx=account"); } if($old_pas != $row['password']) { $_SESSION['message'] = 'your password does not match.'; header('Location: index.php?fx=account'); } if($new_pas != $new_pas2) { $_SESSION['message'] = 'The new passwords dont match.'; header("Location: index.php?fx=account"); } } So when I don't fill in my form (leave every field empty); I get the message 'your password does not match.', but it should give that not all fields are filled in. I really do not see my mistake.. Quote Link to comment https://forums.phpfreaks.com/topic/201182-some-simple-mistake-with-empty/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 9, 2010 Share Posted May 9, 2010 You need exit; statements after every header redirect to prevent the remainder of the code on the page from being executed while the browser is requesting the URL that is the target of the header() redirect. Quote Link to comment https://forums.phpfreaks.com/topic/201182-some-simple-mistake-with-empty/#findComment-1055507 Share on other sites More sharing options...
arbitter Posted May 10, 2010 Author Share Posted May 10, 2010 Oh I see. I had just fixed it by using 'elseif', but this is easier. I thought the site got redirected imediatly, so it wouldn't be necessary to exit the script. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/201182-some-simple-mistake-with-empty/#findComment-1055880 Share on other sites More sharing options...
PFMaBiSmAd Posted May 10, 2010 Share Posted May 10, 2010 A header() statement JUST sends a header to the browser. It has no affect on the php script, which continues execution after the header() statement until it gets to the end of the file or an exit/die statement. Quote Link to comment https://forums.phpfreaks.com/topic/201182-some-simple-mistake-with-empty/#findComment-1056086 Share on other sites More sharing options...
arbitter Posted May 11, 2010 Author Share Posted May 11, 2010 A header() statement JUST sends a header to the browser. It has no affect on the php script, which continues execution after the header() statement until it gets to the end of the file or an exit/die statement. aaaah I see! I didn't know that, but I guess you already knew I didn't know that. Thanks for the further explanation! Quote Link to comment https://forums.phpfreaks.com/topic/201182-some-simple-mistake-with-empty/#findComment-1056738 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.