Frederick wrote:

Just remove the + in the w+

Okay.. Now.. how can I get it so it writes from my first file??

    Uh.. Where do I start? 🙂

    Okay, first one:

    <form method="post" action"<?php $handle ?>"> 
    

    <?php $handle ?> doenst do anything(you dont print it). This translates to:
    <form method="post" action""> and you are missing "="-sign after action.

    Action should be the scriptname where you want to send the information to be processed. I think you tried to send it to $handle which is filehandle for your textfile.

    In this case you probably want to send it to the same script where you are sending from:

    <form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
    

    There was so much missing and Im more quicker to code than explain (and I'm tired) so heres(hopefully) the working script..

    Before the script heres a few tips:

    • Learn how to process forms with PHP. Study $GET, $POST and other predefined variables.

    • Do the form processing at the beginning of the script.

    <?php
    $filename = '../txt/grad.txt';
    $msg = '';
    
    if (isset($_POST['FCKeditor1'])) {
    	// took out the is_writable bcos the next check will fail if it isnt
    	if (!$handle = fopen($filename, 'w')) {
    		$msg = "Cannot open file ($filename)";
    	} else {
    		if (fwrite($handle, $_POST['FCKeditor1']) === TRUE) {
    			$msg = "Cannot write to file ($filename)";
    		} else {
    			$msg = 'Wrote syccesfully to file ('.$filename.')';
    			$content = $_POST['FCKeditor1'];
    			fclose($handle);
    		}
    	}
    }
    
    // If $content is not yet set and $filename exists, retrieve the contents of the file
    if (!isset($content) && file_exists($filename)) {
    	$content = file_get_contents($filename);
    } else {
    	$content = '';
    }
    
    include('../includes/header.php');
    include('../includes/sidebar.php');
    
    
    <td id="main_content">
      <span class="heading_text">TxTCmS Administration</span><br />    <br />
    <?php 
    // Print status message if there is any.
    if (!empty($msg)) {
    	echo '<strong>'.$msg.'</strong';
    }
    
    include("../FCKeditor/fckeditor.php"); ?>
    
    <form method="post" action"<?php echo $_SERVER['SCRIPT_NAME'];?>">
    
    <?php 
    $oFCKeditor = new FCKeditor('FCKeditor1') ;
    $oFCKeditor->BasePath = '../FCKeditor/';
    $oFCKeditor->Height = '350' ;
    $oFCKeditor->Value = $content;
    $oFCKeditor->Create() ;
    ?>
    
    <input type="submit" name="submit" value="Save Page"></input>
    </form></td>
    </table>
    
    <?php include('../includes/footer.php')?> 
    

      Awesome! Thank You! That Worked. However, you forgot 1 closing php statment

      ?>

      so for anyone else who is trying this you can use

      <?php include('../includes/header.php')?>
      
      <?php include('../includes/sidebar.php')?>
      
      
      <td id="main_content">
      
      
      
        <span class="heading_text">TxTCmS Administration</span><br />    <br />
        <?php
      include("../FCKeditor/fckeditor.php") ;
      ?>
      
      <?php
      $body = implode('', file('../txt/grad.txt'));
      ?>
      
      <form method="post" action="saveData.php">
      
      <?php $oFCKeditor = new FCKeditor('FCKeditor1') ;
      $oFCKeditor->BasePath = '../FCKeditor/';
      $oFCKeditor->Height = '350' ;
      $oFCKeditor->Value = $body;
      $oFCKeditor->Create() ;
      ?>
      
      <input type="submit" name="submit" value="Save Page"></input>
      
      </form></td>
      
      </table>
      
      <?php include('../includes/footer.php')?>

      However remember to take out my Include statements, for my header, sidebar, and footer.

      THANK YOU SO MUCH FOR HELPING!!!

        Yeah I forgot a closing statement. Its 5:35 am in the morning 🙂

        Why are you doing this:

        $body = implode('', file('../txt/grad.txt')); 
        

        ..instead of this:

        $body = file_get_contents('../txt/grad.txt');
        

        file_get_contents() will give you the contents as a string. file() gives an array (separate lines) and you dont need that(thats why you are joining them with implode() to get a string).

          cahva wrote:

          Yeah I forgot a closing statement. Its 5:35 am in the morning 🙂

          Why are you doing this:

          $body = implode('', file('../txt/grad.txt')); 
          

          ..instead of this:

          $body = file_get_contents('../txt/grad.txt');
          

          file_get_contents() will give you the contents as a string. file() gives an array (separate lines) and you dont need that(thats why you are joining them with implode() to get a string).

          Oh! The reason why I am doign that is because, i am using and older version of PHP. Our server, is managed by someone else, and that person will not let me lay a finger on the server, to upgrade it.... unfortuantly...

            MillerTech wrote:

            Oh! The reason why I am doign that is because, i am using and older version of PHP. Our server, is managed by someone else, and that person will not let me lay a finger on the server, to upgrade it.... unfortuantly...

            Hmm.. It should work still if the version is 4.3.1. file_get_contents is available from 4.3.0.
            Theres really no reason not to upgrade the version to latest 4.x series. Theres no major changes in functions, just bug and security fixes.

              one last little problem. Whenever i stick in a hyperlink or an image or somthing it always puts a / either in the " at both the beginning and the end.

              It outputs like this:

              <a href=/"emailmehere@email.com/">Name Here</a>

              The code is fine before i save it.

              I know that i need to use the stripslashes function, however I am not too sure on where to put it.

              Any thoughts?

                You may need to use stripslashes() to get rid of those slashes. It happens when magic quotes are on. Read the manual about it.

                  4 days later
                  cahva wrote:

                  You may need to use stripslashes() to get rid of those slashes. It happens when magic quotes are on. Read the manual about it.

                  I have been playing with this for the past couple days.. and can't get anything.. any suggestions...

                    11 days later

                    Here is the script code you graciously shared.

                    cahva wrote:
                    <?php
                    $filename = '../txt/grad.txt';
                    $msg = '';
                    
                    if (isset($_POST['FCKeditor1'])) {
                    	// took out the is_writable bcos the next check will fail if it isnt
                    	if (!$handle = fopen($filename, 'w')) {
                    		$msg = "Cannot open file ($filename)";
                    	} else {
                    		if (fwrite($handle, $_POST['FCKeditor1']) === TRUE) {
                    			$msg = "Cannot write to file ($filename)";
                    		} else {
                    			$msg = 'Wrote syccesfully to file ('.$filename.')';
                    			$content = $_POST['FCKeditor1'];
                    			fclose($handle);
                    		}
                    	}
                    }
                    
                    // If $content is not yet set and $filename exists, retrieve the contents of the file
                    if (!isset($content) && file_exists($filename)) {
                    	$content = file_get_contents($filename);
                    } else {
                    	$content = '';
                    }
                    
                    include('../includes/header.php');
                    include('../includes/sidebar.php');
                    
                    
                    <td id="main_content">
                      <span class="heading_text">TxTCmS Administration</span><br />    <br />
                    <?php 
                    // Print status message if there is any.
                    if (!empty($msg)) {
                    	echo '<strong>'.$msg.'</strong';
                    }
                    
                    include("../FCKeditor/fckeditor.php"); ?>
                    
                    <form method="post" action"<?php echo $_SERVER['SCRIPT_NAME'];?>">
                    
                    <?php 
                    $oFCKeditor = new FCKeditor('FCKeditor1') ;
                    $oFCKeditor->BasePath = '../FCKeditor/';
                    $oFCKeditor->Height = '350' ;
                    $oFCKeditor->Value = $content;
                    $oFCKeditor->Create() ;
                    ?>
                    
                    <input type="submit" name="submit" value="Save Page"></input>
                    </form></td>
                    </table>
                    
                    <?php include('../includes/footer.php')?> 
                    

                    I made one or two corrections. And configured it for my FCK install/needs.

                    However, the one thing it does not seem to do is reload $content. After making edits and posting the changes, the target $filename is modified. The page reloads itself, but this time $content is blank.

                    Why? I had expected it to retrieve the $filename, in order to provide visual proof the edits occurred (in addition to the message line that gets inserted).

                    Indeed the code has a line to check if $filename exists and, if so, load it as $content. Yet, it does not.

                    Thanks for any help on this point.

                      LearningPHP wrote:

                      Here is the script code you graciously shared.

                      I made one or two corrections. And configured it for my FCK install/needs.

                      However, the one thing it does not seem to do is reload $content. After making edits and posting the changes, the target $filename is modified. The page reloads itself, but this time $content is blank.

                      Why? I had expected it to retrieve the $filename, in order to provide visual proof the edits occurred (in addition to the message line that gets inserted).

                      Indeed the code has a line to check if $filename exists and, if so, load it as $content. Yet, it does not.

                      Thanks for any help on this point.

                      Now When you make some kind of link, does it act funny? does it put some kind of slashes in, that you need to add

                      stripslashes()

                        Nope, I have no problem with slashes being introduced. So I haven't had to apply the stripslashes function anywhere.

                        My problem is that I after posting the form, the page reloads but without including the (recently changed) target tile. Why?

                          Write a Reply...