FRIHOSTFORUMSSEARCHFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a 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.


Last edited by Stubru Freak on Wed Apr 26, 2006 5:16 pm; edited 1 time in total
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

I need little help - are someone from New York here!
The Sound Of Music Project - I need your help!
Help me, cheat me and earn 10 Frish!
CALVIN AND HOBBES FANS: need some help again.
Need Everyones Help

I need your help! - audio stuff
PHP/MySQL: Apostrophe problem
Web Designers: I need a little help and a few thoughts!
Need help fixing some js.. F$500 (long post)
need help on PHP or HTML...

Dreamweaver Help!
Need Gimp Help
Help with Website
Need some help with FTP
need php help save command

I is stupid, need domain help :P
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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