Jump to content

Echoing Twice?


Sesquipedalian

Recommended Posts

Hi.. Well, I am trying to make something that you enter in the filename of a file you want to edit, then a textarea comes up with what's on that file, you edit it, then it edit's the file.. Well, it's not working, first off, for some reason it is echoing twice instead of once, and it won't edit the file correctly (I'm guessing because there are two different forms named the same thing)..

[b]form.php[/b]
[code=php:0]<?php
error_reporting(2047); // debug
echo "<form id='form1' name='form1' method='post' action='edit.php'>Filename:<br>"
. "<input name='filename' type='text' id='filename' value='' />"
. "<input name='subfilename' type='hidden' id='subfilename' value='1' />"
  . "<input type='submit' name='Submit' value='Submit' /></form>";
?>[/code]


[b]edit.php[/b]
[code=php:0]<?php
error_reporting(2047); // debug
$test = new edit;
$test->edit();
class edit
{
    function edit(){
   
        if(isset($_POST['subfilename'])){
        $this->procTextArea();
        }
        else if(isset($_POST['subeditfile'])){
        $this->procEditFile();
        }
    }
    function procTextArea(){
$filename = $_POST['filename'];
    $file=fopen($filename, "r");
    $read=fread($file, 900000);
            echo "Editing: <b>" . $filename . "</b><br>"
                . "<form id='form1' name='form1' method='post' action='edit.php'>"
                . "Edit:<br /><textarea name='edit' id='edit'>" . $read . "</textarea>"
                . "<input name='subeditfile' type='hidden' id='subeditfile' value='1' />"
    . "<input name='filename' type='hidden' id='filename' value='" . $filename . "' />"
                . "<input type='submit' name='Submit' value='Submit' /></form>";
    }
    function procEditFile(){
$filename = $_POST['filename'];
        $edit = $_POST['edit'];
        $edit_file=fopen($filename, "w+");
        $file_read=fread($edit_file, 90000);   
            if (!$edit==$file_read && !$file_read==""){
                fwrite($edit_file, $edit);
               
            } else if (!$file_read==$edit){
                echo "Error,<br><br>" . $edit . "<br><br>Could not be written to "
                    . $filename;

            } else if ($file_read==$edit) {
                echo "Success,<br><br>" . $edit . "<br><br>has been written to "
                    . $filename;
            }
        fclose($edit_file);
        }       
   
    };
?> [/code]
Link to comment
https://forums.phpfreaks.com/topic/14792-echoing-twice/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.