PHP Open Stream Error

Discussion in 'PHP' started by loglaughs, Dec 8, 2017.

  1. loglaughs


    Dec 8, 2017
    Likes Received:
    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:
    <!DOCTYPE html>
    <html lang="en">
        .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 {
      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;
      <link href="" rel="stylesheet">
      <meta charset="UTF-8" />
      <title>Contact | Just Search Around</title>
      <p class="site-header"></p>
      <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 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>
          <input type="submit" form="contactForm" value="Submit">
    $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);
    loglaughs, Dec 8, 2017
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.