Forum Moderators: coopster
i am getting a parse error on the line that contaisn the php close tag?>
i deleted it, and i got the same error on the line that contains, fclose($a);
can anyone see any problems looking at this script, it should work! if the name field and the message field are empty then it takes the user to error.php if not they get the printed message, anyone help?
[edited by: jatar_k at 5:25 pm (utc) on May 2, 2004]
[edit reason] generalized urls [/edit]
Your shout has been added to the box, Click Here to go view the box
Warning: Cannot modify header information - headers already sent by (output started at /home/www/juttuffi/PHP/add.php:4) in /home/www/juttuffi/PHP/add.php on line 6
i am totally new to php, this is my first real script that can be used by anyone and i honestly cannot see what the problem is, if anyone could point it out i would be grateful.
thanks
chris
print "Your shout has been added to the box, <a href=$box>Click Here</a> to go view the box";
is being sent to the browser because the check is after that, so i should probably put that line right at the bottom of the code? or before the fwrite()
thanks for pointing that out with any luck it will work (hopefully) i'v been on with this script all day.
I dont suppose you would know how i could nest another if statement in there somewhere
i was hoping to find something that would delete the contents of the file and execute the following
if filesize() > 512 { delete contents of file }
just to stop the file getting too big, also does php take 512 as kb or just bytes?
your code might look like this
<?php
$filename = "test.txt";
if(filesize($filename) > 512) {
unlink($filename);
}
$box = "http://www.example.com/PHP/shout.php"; // URL of shout box
if (empty($name) ¦¦ empty($message)) {
header( "Location: [example.com...] );
}
print "Your shout has been added to the box, <a href=$box>Click Here</a> to go view the box";
else {
$a = fopen( $filename, "a") or die ("could not open $filename for writing please check file permissions");
flock($a, LOCK_SH);
fwrite($a, "<font face=verdana size=2><b>$name</b> : $message</font>
<hr noshade size=1>");
flock($a, LOCK_UN);
fclose($a);
?>
[edited by: jatar_k at 5:26 pm (utc) on May 2, 2004]
[edit reason] generalized urls [/edit]
$a = fopen($filename, "a")
i want things to appear at the end of the file so i used a, i dont want to replace or overwrite data which i think w does, so i need to delete the contents when it gets to a certain size, it says i do not have permission
is this because i am opening the file to be appended? i understand it it just wont bloody work, can anyone at all shed some light on the error the codes below, thanks to everyone who has helped out so far, this has really gotten me into php, i'm definately gonna get me a decent book and read up on it!
<?php
$error = "http://www.example.com/PHP/error.php"; // location of error page
$filename = "data.txt";
$box = "http://www.example.com/PHP/shout.php"; // URL of shout box
$max = 2048; // maximum size (bytes) of data.txt file
if(filesize($filename) > $max) {
unlink($filename);
}
if (empty($name) ¦¦ empty($message)) { header( "Location: $error" );
} else {
print "Your shout has been added to the box, <a href=$box>Click here</a> to go back the the box ";
$a = fopen( $filename, "a") or die ("could not open $filename for writing please check file permissions");
flock($a, LOCK_SH);
fwrite($a, "<font face=verdana size=2><b>$name</b> : $message</font>
<hr noshade size=1>");
flock($a, LOCK_UN);
fclose($a);
}
?>
[edited by: jatar_k at 5:26 pm (utc) on May 2, 2004]
[edit reason] generalized urls [/edit]