wattsup88 Posted November 27, 2007 Share Posted November 27, 2007 Hey guys! I cant get the fopen function to work in this block of code... Any idea why? or any alternative ideas... Just trying to create a newsfeed.... <?php //this should all go into one file. I would name it addnews.php if($HTTP_POST_VARS['submit']) { if($HTTP_POST_VARS['password'] == 'pass') { 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","<BR>",$line); $line .= "\r\n"; fwrite($fp, $line); if(!fclose($fp)) { echo "Error closing file!"; exit; } } else { echo "Bad Password"; } } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted November 27, 2007 Share Posted November 27, 2007 Make sure the file is writable. You might also want to describe what cant get the fopen function to work actually meens. What is happening. PS: $HTTP_POST_VARS has for many years been depricated in favour of $_POST. Quote Link to comment Share on other sites More sharing options...
wattsup88 Posted November 29, 2007 Author Share Posted November 29, 2007 By "work" i mean that this block always returns true and therefore echos the message and exits. I want this block to return false (see code above). if(!$fp) { echo "Error opening file!"; exit; } Also i believe the file is writable but how do i tell... I right-clicked and check and the "read-only" box is not checked if thats what you mean... oh and the folder on my server is writable of course... and yes i know about the $_POST thing i copied and pasted some old code and i havent replaced it... Thanks for bringing that to my attention though Sorry to be so noobish but i have never dealt with this function before... Thanks for the help already and Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.