3 Replies - 448 Views - Last Post: 01 September 2012 - 07:18 PM Rate Topic: -----

#1 weazl  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 18-June 12

how to write to a file without rewriting it

Posted 01 September 2012 - 06:03 PM

I am making a php script which creates a file and then writes to it however i find that whenever i look at the file i only see the newest data written to the file.I want to write to the file without rewriting it completely and just writing to the end ofthe file.Here is my code
<?php
$message = $_POST['message'];
$name = $_POST['name'];
if(empty($message) === false or empty($name) === false){
$FILE = fopen('filecre.html', 'a');
fwrite($FILE, '<b>' .$name .'</b> says:<br />' .$message .'<p></p>');
fclose($FILE);
echo 'FIle written to.';
}
?>
<!DOCTYPE html>
<html>
<head>

</head>
<body>
<form action='' method="post">
<input type="text" name="name" />
<textarea name="message"></textarea>
<input type="submit" value="Write to File"/>
</form>
</body>
</html>



Thanks in advance.

Is This A Good Question/Topic? 0
  • +

Replies To: how to write to a file without rewriting it

#2 William_Wilson  Icon User is offline

  • lost in compilation
  • member icon

Reputation: 205
  • View blog
  • Posts: 4,807
  • Joined: 23-December 05

Re: how to write to a file without rewriting it

Posted 01 September 2012 - 06:32 PM

Is this the exact code you are using?
When I run it, the text appends to the file as expected.
Was This Post Helpful? 2
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3105
  • View blog
  • Posts: 10,906
  • Joined: 08-August 08

Re: how to write to a file without rewriting it

Posted 01 September 2012 - 06:54 PM

There are no line feeds in your code, so you will not see additional lines. Your text editor may not wrap text automatically, so the output may look like it isn't changing. If you scroll to the right you'll see that additional text.
Was This Post Helpful? 1
  • +
  • -

#4 weazl  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 12
  • Joined: 18-June 12

Re: how to write to a file without rewriting it

Posted 01 September 2012 - 07:18 PM

Sorry for all my troubles as CTphpnwb said i wasn't looking properly

@William_Wilson
I'm building a chat box.The comments will be in an html document which will be loaded in to a div by jquery's .ajax function and the file will be rewritten by php
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1