C
chrisshields
Guest
Adding news to site in PHP
I am using some php to create a news page on our clan website. The html/php looks like this:
<?
if($HTTP_POST_VARS['submit']) {
if($HTTP_POST_VARS['password'] == 'test') {
if(!$HTTP_POST_VARS['name']) {
echo "You must enter a name";
exit;
}
if(!$HTTP_POST_VARS['news']) {
echo "You must enter some news";
exit;
}
if(strstr($HTTP_POST_VARS['name'],"|")) {
echo "Name cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['news'],"|")) {
echo "News cannot contain the pipe symbol - |";
exit;
}
$fp = fopen('news.txt','a');
if(!$fp) {
echo "Error opening file!";
exit;
}
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line = str_replace("\r\n","
",$line);
$line .= "\r\n";
fwrite($fp, $line);
if(!fclose($fp)) {
echo "Error closing file!";
exit;
}
} else {
echo "Bad Password";
}
}
?>
<FORM ACTION="addnews.php" METHOD="POST" NAME="newsentry">
Your name:
<INPUT TYPE="text" SIZE="30" NAME="name">
The News:
<TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA>
News Password:
<INPUT TYPE="password" SIZE="30" NAME="password">
<INPUT TYPE="submit" NAME="submit" VALUE="Post it!">
</FORM>
The file is named addnews.php and is located in the root directory of the site (www.site.barrysworld.com/addnews.php). However, when the script is executed, "Error opening file" is returned. This is from:
"$fp = fopen('news.txt','a');
if(!$fp) {
echo "Error opening file!";
exit;
Where does the news.txt file have to be placed for this to work? What am I doing wrong?
Thanks,
Chris Shields
I am using some php to create a news page on our clan website. The html/php looks like this:
<?
if($HTTP_POST_VARS['submit']) {
if($HTTP_POST_VARS['password'] == 'test') {
if(!$HTTP_POST_VARS['name']) {
echo "You must enter a name";
exit;
}
if(!$HTTP_POST_VARS['news']) {
echo "You must enter some news";
exit;
}
if(strstr($HTTP_POST_VARS['name'],"|")) {
echo "Name cannot contain the pipe symbol - |";
exit;
}
if(strstr($HTTP_POST_VARS['news'],"|")) {
echo "News cannot contain the pipe symbol - |";
exit;
}
$fp = fopen('news.txt','a');
if(!$fp) {
echo "Error opening file!";
exit;
}
$line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
$line .= "|" . $HTTP_POST_VARS['news'];
$line = str_replace("\r\n","
",$line);
$line .= "\r\n";
fwrite($fp, $line);
if(!fclose($fp)) {
echo "Error closing file!";
exit;
}
} else {
echo "Bad Password";
}
}
?>
<FORM ACTION="addnews.php" METHOD="POST" NAME="newsentry">
Your name:
<INPUT TYPE="text" SIZE="30" NAME="name">
The News:
<TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA>
News Password:
<INPUT TYPE="password" SIZE="30" NAME="password">
<INPUT TYPE="submit" NAME="submit" VALUE="Post it!">
</FORM>
The file is named addnews.php and is located in the root directory of the site (www.site.barrysworld.com/addnews.php). However, when the script is executed, "Error opening file" is returned. This is from:
"$fp = fopen('news.txt','a');
if(!$fp) {
echo "Error opening file!";
exit;
Where does the news.txt file have to be placed for this to work? What am I doing wrong?
Thanks,
Chris Shields