Jump to content

PHP is skipping code


awaise17

Recommended Posts

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.php
Then i just used echo statement but it is also not working...so php is skipping the code under fwrite...

Link to comment
https://forums.phpfreaks.com/topic/281537-php-is-skipping-code/
Share on other sites

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');

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.