write form input to a text file.

I’m working on an assignment so this does not have to be secure and I cannot work with a database, it has to be a text file.

I keep getting an error message on line 17, I know its probable simple but can’t find the error

Then once the user has created a a username and password and they need to sign in, how would I validate the username and password with the text file?

[php]<?php

if(isset($_POST[‘submit_btn’]))
{
$username = $_POST[‘name’];
$password = $_POST[‘pwd’];
$text = $username . “,” . $password . “\n”;
$fp = fopen(‘accounts.txt’, ‘a+’);

if(fwrite($fp, $text))  {
    echo 'Your information has been saved';

}

fclose ($fp);
}

Please enter your information to create a Login account

Login Name: Password:

?>[/php]

you need to close php after the last closing bracket before the html starts.
Move the ?> up before the form, not after.

Hope that helps,
Red :wink:

empty

I would just store it as a json string, then it’s easy to revert it back to an array or an object to compare with the submitted data. Look into json_encode/json_decoda

Sponsor our Newsletter | Privacy Policy | Terms of Service