PHP Open Stream Error

Joined
Dec 8, 2017
Messages
1
Reaction score
0
I am trying to make a simple contact form for a simple website, just a little messing around. After getting all the code set up I ran the form and I got this error:
"Warning: fopen(contactinfo.txt): failed to open stream: Permission denied in /home/cabox/workspace/contact/answers.php on line 2 Unable to open file!"
I am using the online "CodeAnywhere" editor.
My full code here:
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
  <style>
    .center {
  text-align: center;
}
.pagination {
  display: inline-block;
}
.pagination a {
  text-decoration: none;
  font-weight: bold;
  padding: 8px 10px;
  border: 1px solid black;
  background: gray;
  color: white;
  float: left;
  font-size: 20px;
  font-family: 'Nunito', sans-serif;
}
.pagination a.active {
  background: #D5D5D5;
  color: black;
}
.pagination a:hover {
  cursor: pointer;
  transform: scale(1.1);
}
.container {
  font-family: 'Nunito', sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  color: black;
} 
  </style>
  <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">
  <meta charset="UTF-8" />
  <title>Contact | Just Search Around</title>
  <p class="site-header"></p>
</head>
  <l></l>
<body>
  <div class="center">
    <div class="pagination">
      <a href="../index.html">Home</a>
      <a href="../calc/calc.html">Calculator</a>
      <a href="../about/about.html">About</a>
      <a href="contact.html" class="active">Contact</a>
    </div>
  </div>
  <div class="container">
    <form action="answers.php" method="POST" id="contactform">
      First Name: <input type="text" name="fname"><br>
      Last Name: <input type="text" name="lname"><br>
      Email: <input type="email" name="email"><br>
      Comment: <br><textarea name="comment" cols="25" rows="5"></textarea>
      <br>
      <input type="submit" form="contactForm" value="Submit">
    </form>
  </div>
</body>
</html>
PHP:
<?php
$myfile = fopen("contactinfo.txt", "w") or die("Unable to open file!");
echo fread($myfile,filesize("contactinfo.text"));
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$break = "<br>";

fwrite($myfile, $firstname);
$break = "<br>";
fwrite($myfile, $lastname);
$break = "<br>";
fwrite($myfile, $email);
$break = "<br>";
fwrite($myfile, $comment);
fclose($myfile);
?>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top