Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder croatiankid's Avatar
    Join Date
    Jan 2006
    Posts
    665
    Thanks
    1
    Thanked 12 Times in 12 Posts

    open file, rewrite it, close it, not working

    I've written this code
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <?
    if (isset($_POST["block1"]))
        {
            
    $newcontent $_POST["block1"];
            
    $fp fopen("block1.txt""w");
            
    fwrite($fp$newcontent);
            
    fclose($fp);
        }
    if (isset(
    $_POST["block2"]))
        {
            
    $newcontent $_POST["block2"];
            
    $fp fopen("block2.txt""w");
            
    fwrite($fp$newcontent);
            
    fclose($fp);
        }
    if (isset(
    $_POST["block3"]))
        {
            
    $newcontent $_POST["block3"];
            
    $fp fopen("block3.txt""w");
            
    fwrite($fp$newcontent);
            
    fclose($fp);
        }
    if (isset(
    $_POST["block4"]))
        {
            
    $newcontent $_POST["block4"];
            
    $fp fopen("block4.txt""w");
            
    fwrite($fp$newcontent);
            
    fclose($fp);
        }
    if (isset(
    $_POST["block5"]))
        {
            
    $newcontent $_POST["block5"];
            
    $fp fopen("block5.txt""w");
            
    fwrite($fp$newcontent);
            
    fclose($fp);
        }
    if (isset(
    $_POST["block6"]))
        {
            
    $newcontent $_POST["block6"];
            
    $fp fopen("block6.txt""w");
            
    fwrite($fp$newcontent);
            
    fclose($fp);
        }
    if (isset(
    $_POST["block7"]))
        {
            
    $newcontent $_POST["block7"];
            
    $fp fopen("block7.txt""w");
            
    fwrite($fp$newcontent);
            
    fclose($fp);
        }
    if (isset(
    $_POST["block8"]))
        {
            
    $newcontent $_POST["block8"];
            
    $fp fopen("block8.txt""w");
            
    fwrite($fp$newcontent);
            
    fclose($fp);
        }
    ?>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>update</title>
    </head>
    <body>
    <p>Update the text.</p>
    <p>index page</p>
    <form id="block1" method="post" action="update.php">
      <p>
        <textarea name="textarea" cols="70" rows="5"><? include("block1.txt"); ?></textarea>
        <input id="save1" value="save" type="submit" />
      </p>
    </form>
    <form id="block2" method="post" action="update.php">
      <p>
        <textarea name="textarea" cols="70" rows="5"><? include("block2.txt"); ?></textarea>
        <input id="save2" value="save" type="submit" />
      </p>
    </form>
    <form id="block3" method="post" action="update.php">
      <p>
        <textarea name="textarea" cols="70" rows="5"><? include("block3.txt"); ?></textarea>
        <input id="save3" value="save" type="submit" />
      </p>
    </form>
    <form id="block4" method="post" action="update.php">
      <p>
        <textarea name="textarea" cols="70" rows="5"><? include("block4.txt"); ?></textarea>
        <input id="save4" value="save" type="submit" />
      </p>
    </form>
    <p>under construction page</p>
    <form id="block5" method="post" action="update.php">
      <p>
        <textarea name="textarea" cols="70" rows="5"><? include("block5.txt"); ?></textarea>
        <input id="save5" value="save" type="submit" />
      </p>
    </form>
    <form id="block6" method="post" action="update.php">
      <p>
        <textarea name="textarea" cols="70" rows="5"><? include("block6.txt"); ?></textarea>
        <input id="save6" value="save" type="submit" />
      </p>
    </form>
    <form id="block7" method="post" action="update.php">
      <p>
        <textarea name="textarea" cols="70" rows="5"><? include("block7.txt"); ?></textarea>
        <input id="save7" value="save" type="submit" />
      </p>
    </form>
    <form id="block8" method="post" action="update.php">
      <p>
        <textarea name="textarea" cols="70" rows="5"><? include("block8.txt"); ?></textarea>
        <input id="save8" value="save" type="submit" />
      </p>
    </form>
    </body>
    </html>
    which doesn't work. Tried editing the first text area and clicked save, it didn't save, no php error. Please get back to me quickly, thanks a ton!

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Code:
        <textarea name="textarea" cols="70" rows="5"><? include("block1.txt"); ?></textarea>
    That doesn't work like you want it to. You have to open and read the file and use echo statements to get it into your HTML markup.

    I like the file() function for this, easy and fast to load a file's contents to an aray. Then simply use a foreach() loop to echo each line.

  • #3
    Regular Coder croatiankid's Avatar
    Join Date
    Jan 2006
    Posts
    665
    Thanks
    1
    Thanked 12 Times in 12 Posts
    are you sure? because, just for your info, the contents of block1.txt show up in the text area. it's just that it doesn't seem to save it. or is it necessary if i want to save it? i don't understand.

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You've not named the textareas
    PHP Code:
    <textarea name="textarea" cols="70" rows="5" name="block1"><? include("block1.txt"); ?></textarea>

  • #5
    Regular Coder croatiankid's Avatar
    Join Date
    Jan 2006
    Posts
    665
    Thanks
    1
    Thanked 12 Times in 12 Posts
    wow thanks, for some reason I gave an id to the form itself, not the actual textarea, which I'm targeting lol


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •