error with writing to this file from the top without...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
synix
Forum Newbie
Posts: 6
Joined: Sun Apr 27, 2003 2:02 pm
Location: medford, ma

error with writing to this file from the top without...

Post by synix »

i'm having an error with writing to this file from the top without deleting text already on the file... i have used all of the fopen functions r,r+,w, etc. none of them work. they all either delete the current text or write from the bottom of the file. it might have something to do with usign fputs().. i duno im lost. =\. here is my php code

Code: Select all

<?
$xname = "$name";
$xmsg = "$msg";
$xemail = "$email";
$xurl = "$url";
$glog = "guestlog.php";
$fp = fopen ($glog, "r+");
$split = " - ";
if (!$xname || !$xmsg) {
echo("one or more required fields were left blank.");
}
if ($xname || $xmsg) {
fputs ($fp,"<a href="mailto:$xemail">$xname</a>$split<a href="$xurl">www</a>$split$xmsg<br><br>");
echo("thank you for your comment, i really appreciate your feedback. <a href="guestlog.php" target="shoutbox">click here</a> to view your comment.");
exit;
}
?>
phpfreak
Forum Commoner
Posts: 30
Joined: Fri Mar 21, 2003 10:28 am
Location: New Jersey,USA
Contact:

Post by phpfreak »

hi there

U are supposed to use "ab" if you want to append.check the following url

http://www.devnetwork.net/forums/viewto ... highlight=


regards
srinivas
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

On a side note, where you've got things like:

Code: Select all

$xname = "$name";
you should get rid of the double quotes as they are totally uneccessary, so that you have things like:

Code: Select all

$xname = $name;
Mac
Post Reply