FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Need a little help





DanielXP
Ok i have this script to edit a page but i keep getting the following error at the bottom.

Warning: Cannot modify header information - headers already sent by (output started at _______________________members/edit.php:53) in _______________________members/edit.php on line 73

The edit code is

Code:
<?php


echo "<form method=post action=edit.php?action=edit><textarea cols=60 rows=20 name=edit>";
$file = "index.php";
$fh = fopen($file, 'r');
$theData = fread($fh, filesize($file));
echo $theData;
fclose($fh);
echo "</textarea><input type=submit value=Edit></form>";
if($_GET['action'] == 'edit')
{
$fh = fopen($file, 'w') or die("can't open file");

$stringData = $_POST['edit'];
fwrite($fh,stripslashes($stringData));
fclose($fh);
}

{
header("Location: edit.php");
}
echo "</center>";
?>


Any one help me please Very Happy
benjad
all header() commands must come before anything else is sent(including all html).

So, in order to fix this, either use a diferent redirect method (meta refresh or javascript?), or re-write the code so the redirect appears before any html is output.

[btw.. please do post any solutions you find... as finding diferent ways to do this has plagued me too...]
DanielXP
Whats the code for an other refresh when theedit has complete?
asiddle423
this javascript method works as i have use it before, i too have found problems with the header command in php just use this instead of the header command

Code:

$URL = "edit.php";
echo '<script language=\"JavaScript\">';
echo 'window.location = "$URL" ';
echo "</script>";
Stubru Freak
asiddle423 wrote:
this javascript method works as i have use it before, i too have found problems with the header command in php just use this instead of the header command

Code:

$URL = "edit.php";
echo '<script language=\"JavaScript\">';
echo 'window.location = "$URL" ';
echo "</script>";


You should always use the header() command unless really impossible.
This script won't work if a user doesn't have javascript.

It isn't really hard. Don't output anything before your header() call. You could use output buffering for example.

And btw the javascript doesn't work. It will try to redirect a user to a page named $URL instead of edit.php.
BlackSkad
Code:
<?php
if (!isset($_POST['submit'])) {
   //submit has not been pressed, so show form
   $file = "index.php";
   $fh = fopen($file, 'r');
   $theData = fread($fh, filesize($file));
   fclose($fh);
?>
   <form method="post" action="edit.php?action=edit">
      <textarea cols="60" rows="20" name="edit">
      <?php echo $theData; ?>
      </textarea>
      <input type="submit" name="submit" value="Edit" />
   </form>
<?php
} elseif ($_GET['action'] == 'edit') {
   //submit has been pressed and the action is edit.
   $fh = fopen('index.php', 'w') or die('can\'t open file');

   $stringData = $_POST['edit'];
   fwrite($fh,stripslashes($stringData));
   fclose($fh);
} else {
   //submit has been pressed, so edit the page
   header ("Location: yourpage.php");
}
?>
DanielXP
on notepad.php?action=edit

the screen is just blank
Related topics
Dreamweaver Help!
Help me, cheat me and earn 10 Frish!
Admin(s), or trustworthy people, I would like a little help.
Some help with the Rules and such
Little help
PS2 Prince of persia the two thrones - HELP RQD!!!
A little help with Debian download??
Help, I need LWP::Simple perl module!!
A little help would be nice...
Web Designers: I need a little help and a few thoughts!
A little Help (Html,CSS, javascript)
need help on PHP or HTML...
Hey Guys, A Little Help?
Need a little help with my JS
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.