www.webdeveloper.com
Results 1 to 2 of 2

Thread: Help needed please

Hybrid View

  1. #1
    Join Date
    May 2003
    Posts
    7

    Help needed please

    Hi all As stated in my other posts i know nothing about php.

    Ok what i am trying to do is make a form that when submited updates a .txt file and then displays the changes in the form. this is the code i have

    Code:
    <form name="title" method="POST" action="<?php echo $_SERVER['SCRIPT_NAME']?>">
    		<div><textarea  name="title" cols="75" rows="15"><?php readfile("../text/homepage/title.txt");?> </textarea></div>
    		<input type="submit" value="Save Changes" name="submit"><input type="reset" value="Reset Form" name="reset"></p>
    </form>
    <?php
    
    if (isset($_POST['submit'])) {
    
    $name = $_POST['title'];
    
    }
    ?>
    
    <?php
    
    if (isset($_POST['submit'])) {
    
    $name = $_POST['title'];
    
    $fp = fopen("../text/homepage/title.txt","w+");
    
    if(!$fp) {
        echo 'Error, the file could not be opened or there was an error creating it.';
        exit;
    }
    }
    ?>
    
    <?php
    
    if (isset($_POST['submit'])) {
    
    $name = $_POST['title'];
    
    $fp = fopen("../text/homepage/title.txt","w+");
    
    if(!$fp) {
        echo 'Error, the file could not be opened or there was an error creating it.';
        exit;
    }
    
    fwrite($fp, $name."\n");
    
    }
    ?>
    
    <?php
    
    if (isset($_POST['submit'])) {
    
    $name = $_POST['title'];
    
    $fp = fopen("../text/homepage/title.txt","w+");
    
    if(!$fp) {
        echo 'Error, the file could not be opened or there was an error creating it.';
        exit;
    }
    
    fwrite($fp, $name."\n");
    
    fclose($fp);
    }
    ?>
    it seems to work somwhat however after clicking save changes the page refreshes but not displaying the changes altho the changes are made in the .txt file, can anyone please help me to get it to display the changes in the form after hitting save changes.

    also how do i get this code to make a new line of test actualy write it on a new line

  2. #2
    Join Date
    Jan 2009
    Posts
    3,346
    It looks like you aren't actually echoing the content to the browser:
    Code:
    <?php readfile("../text/homepage/title.txt");?>
    Should be:
    Code:
    <?php echo readfile("../text/homepage/title.txt");?>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles