Jump to content


Photo

Echoing Twice?


  • Please log in to reply
4 replies to this topic

#1 Sesquipedalian

Sesquipedalian
  • Members
  • PipPipPip
  • Advanced Member
  • 90 posts

Posted 16 July 2006 - 08:59 PM

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)..

form.php
<?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>";
?>


edit.php
<?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);
        }        
    
    };
?>


#2 cunoodle2

cunoodle2
  • Members
  • PipPipPip
  • Advanced Member
  • 602 posts

Posted 17 July 2006 - 06:02 AM

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??

If the code was working and now it's not, something changed. Did you change any code?

yeah, just a little bit, I am trying to start from beginning and trace my steps to see what i did wrong unless you see it.


#3 Sesquipedalian

Sesquipedalian
  • Members
  • PipPipPip
  • Advanced Member
  • 90 posts

Posted 17 July 2006 - 06:13 PM

Whenever I write echo it echo's twice. ;] I found out why though.

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 17 July 2006 - 06:36 PM

is it becouse i's in the while loop somewere?

tell us then cheers.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 Sesquipedalian

Sesquipedalian
  • Members
  • PipPipPip
  • Advanced Member
  • 90 posts

Posted 18 July 2006 - 02:33 AM

<?php
error_reporting(2047); // debug
$test = new edit;
$test->edit();
class edit
{
    function edit(){

If I remove
$test->edit();

Then it only echo's once.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users