awaise17 Posted August 25, 2013 Share Posted August 25, 2013 (edited) i am creating a login form in which the login credentials will be sent from index.php file to login.php and after validating that the user does not have sent empty fields, he will be directed to my index.php file. Here is my code <?php$email = $_POST['email'];$pass = $_POST['pass'];if($email=='' || $pass==''){ header("Location: index.php?view=err"); }else{ $data = "Email = $email | Password = $pass".PHP_EOL; //open the file and choose the mode $fh = fopen("users.txt", "a"); //writing to the file fwrite($fh, $data); //close the file fclose($fh); header("Location: index.php") ;// echo"code is working fine"; }?> The upper half of the code is working fine. It is redirecting the user if he leaves some fields empty but it is not working for the else condition.It saves the data to users.txt file but it does not redirect the user to index.phpThen i just used echo statement but it is also not working...so php is skipping the code under fwrite... Edited August 25, 2013 by awaise17 Quote Link to comment https://forums.phpfreaks.com/topic/281537-php-is-skipping-code/ Share on other sites More sharing options...
jcbones Posted August 25, 2013 Share Posted August 25, 2013 2 problems. 1. You are not closing the file after fwrite, because fclose is inside of a comment. 2. header expects an actual URI, with relative URI's it works sometimes, but isn't reliable. So, spell out that protocol. header('Location: http://mysite.com/index.php'); Quote Link to comment https://forums.phpfreaks.com/topic/281537-php-is-skipping-code/#findComment-1446682 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.