Jump to content

Archived

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

Sesquipedalian

Echoing Twice?

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]

Share this post


Link to post
Share on other sites
Sorry..just for a little clarification...

What is your form doing?
What are you EXPECTING it to do that it is not?

I know that you said it was echoing twice but what is it echoing twice?  Like a certain line in there??

Share this post


Link to post
Share on other sites
is it becouse i's in the while loop somewere?

tell us then cheers.

Share this post


Link to post
Share on other sites
[code=php:0]
<?php
error_reporting(2047); // debug
$test = new edit;
$test->edit();
class edit
{
    function edit(){[/code]

If I remove
[code=php:0]
$test->edit();[/code]

Then it only echo's once.

Share this post


Link to post
Share on other sites

×

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.