Problem in getting form data and storing it in a text file

I have got LAMP server installed on my Ubuntu 16.04 machine.

I have created a basic HTML form that is required to accept the first and the last name of the user and save the data in a text file.

Now the issue is that when the form data is entered and SUBMIT button is hit, then the page redirections take place as defined by the script but the file in which I am supposed to store the data is not created.

Here is the code that I have written

<html>
<head>
<title>Text Input Control</title>
</head>
<body>
<form action="confirm_send.php", method="post">
First name:  <input type="text" name="first_name" />
<br>
Last name:  <input type="text" name="last_name" />
<input type="submit" value="submit" name="submit">
</form>

</body>
</html>

<?php
$Fname = $_POST["first_name"];
$Lname = $_POST["last_name"];
$fp = fopen('data.csv', 'a');
fwrite($fp, $Fname);
fclose($fp);
?>

the file data.csv is not created once SUBMIT is done. I also checked the HOME directory it was not found. What’s the catch?

insufficint file (resp. directory) permissions and disabled error reporting.

I am trying to give permission to the html folder in /var/www/ directory using

sudo chmod -R 777 *

There is an error message saying that

sudo: /etc/sudoers is world writable
sudo: no valid sudoers sources found, quitting
sudo: unable to initialize policy plugin

What needs to be done next

HTML folders don’t need to be world writeable. You should never be using 777 for any files as that gives everyone rights to do what they line with your copy of your files.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.