Php Put Content - strange error

I have this simple web content editor written in php

[code]<?php

if (isset($_POST['home']))
{
    
    if (file_put_contents('homecontent.txt', $_POST['homecontent']) !== FALSE)            echo '<p class="success">Home Content Saved Successfully!</p>', "\n";
}

$homecontent = file_get_contents('homecontent.txt');

if (isset($_POST['header']))
{
    
    if (file_put_contents('headercontent.txt', $_POST['headercontent']) !== FALSE)            echo '<p class="success">Header Content Saved Successfully!</p>', "\n";
}

$headercontent = file_get_contents('headercontent.txt');


if (isset($_POST['cssfile']))
{
    
    if (file_put_contents('style.txt', $_POST['cssfile']) !== FALSE)            echo '<p class="success">Style.css Saved Successfully!</p>', "\n";
}

$cssfile = file_get_contents('style.txt');
?>

Here you can edit your homepage text:

<?php echo $homecontent ?>

Save changes

Here you can edit your header content:

<?php echo $headercontent ?>

Save changes

Here you can edit style.css file:

<?php echo $cssfile ?>

Save changes

[/code]

The problem in this script is that it execute first 2 forms, but the last 1 fails. However, it creates the 3rd file when executed for the first time. If I add new content it gets erased after submit. It cannot be a server specific becasue I tested it on 3 different server. Error log is not recording anything because I get success message.

You named the last text area and the submit the exact same name so the submit button is overwriting the text area to nothing.

Okay, I changed that, but no luck. So I created new file with single form.

[code]<?php error_reporting(E_ALL);
ini_set(‘display_errors’, 1);
?>

<?php if (isset($_POST['cssfile'])) { if (file_put_contents('style.txt', $_POST['cssfile']) !== FALSE) echo '

Style.css Saved Successfully!

', "\n"; } $csscontent = file_get_contents('style.txt'); ?>

Here you can edit style.css file:

<?php echo $csscontent ?>

Save changes

[/code]

But even this doesn’t work. I get the same success message :frowning:

No, you changed it wrong. Look at what your doing closely and you should see the problem

The only thing you needed to change was the name of the submit button and line 20 and

if (isset($_POST[‘cssfile’])) to the same name as the submit button

Thanks for all the help. I finally got it working. Here is the correct code

[code] ?>

<?php if (isset($_POST['cssfile'])) { if (file_put_contents('style.txt', $_POST['csscontent']) !== FALSE) echo '

Style.css Saved Successfully!

', "\n"; } $csscontent = file_get_contents('style.txt'); ?>

Here you can edit style.css file:

<?php echo $csscontent ?>

Save changes

[/code]

Silly oversight problem, wasted a day!

Sponsor our Newsletter | Privacy Policy | Terms of Service