Page 1 of 2

$end=fixed | now => $file undefined error

Posted: Tue Jun 15, 2004 7:02 pm
by ol4pr0
Tried differant things.. but i just cant find my error.

i knows its in the write_news part but.. cant find it did try the most common thing by adding the } at the end however that didnt seem to do the trick
Parse error: parse error, unexpected $end on line 70
line 70 is ofcourse the last line..

Code: Select all

<?
require_once("inc/config.inc");
switch($shownews) 
	{
		case 'default':
		echo '<html><head><title>"'.$site_name.'" News</title></head>';
		echo '<body bgcolor="#EEEEEE" text="#000000">';
		echo '<center><h1>'.$site_name.' News</h1></center>';
		$gd = getdate();
		$filename = "news/news".$gd["mday"]."-".$gd["mon"]."-".$gd["year"].".txt";
		if (!((file_exists($filename)) || is_file($file_name) || is_readable($filename)))
			{
			die(":NEWS FILE ERROR::");
			}
		$data=file($filename);
		echo "<table align="center">";
		echo "<tr><td><h1>".$data[0]."</h1></td></tr>";
		echo "<tr><td>";
		for ($i=1;$i<count($data);$i++)
			{
			echo "</table>";
			}
		break;

		case 'write_news':
		echo '<html><head><title>"'.$site_name.'" News</title><head>';
		echo '<body bgcolor="#EEEEEE" text="#000000">';
		echo '<table width="600" border="1" align="center" bordercolor="#000000" cellspacing="0">';
		echo '<tr><td width="300" height="146" bgcolor="#EEEEEE">';
		echo '<form name="write_news" method="post" action="write_admin_news.php">';
		echo '<table width="48%" border="0" algin="center">';
		echo '<tr><td><center><b>Add "'.$site_name.'" News</b></center></td></tr>';
		echo '<tr><td><center><input typ="text" name="headline" size="35">';
		echo '</center></td></tr>';
		echo '<tr><td><center><b>Main Article</b></center></td></tr>';
		echo '<center><TEXTAREA NAME="news" ROWS="7" COLS="30"></TEXTAREA></center></td></tr>';
		echo '<tr><td><div align="center">';
		echo '<input type="submit" name="submit" value="submit">';
		echo '</div></td></tr></table></form></td>';
		echo '<td width="300" height="146" bgcolor="#EEEEEE">';
		echo '<form name="old_news" method="post" action="write_admin_news.php">';
		echo '<p align="center">';
		echo '<select name="select"size="1"><option value="0">Old News</option>';
		if (!((file_exists("news")) || (is_dir("news"))))
		{
		mkdir("news",0700);
		}
		else
			{
			$filelist = opendir('news'/');
			while($file=readdir($file));
				{
				if (is_file($file))
				{
				echo "<option value="".$file."" >".$file."(".$filetype($file).")</option>";
				}
			}
		}
		?>
		</select></p>
		<p align="center"><input type="radio" name="radio" value="delete">
		<b>Delete!</b></p>
		<p align="center">
		<input type="submit" name="submit2" value="submit"></p></form></td></tr></table>
		</body></html>
		<?
	break;
	}
}
?>

Posted: Tue Jun 15, 2004 7:04 pm
by infolock
$filelist = opendir('news'/');

should be

$filelist = opendir('news/');

Posted: Tue Jun 15, 2004 7:11 pm
by ol4pr0
stupid as it is.. this forum made me see my mistake more quickly than my editplus, maby i should use another editor ?

Anybody got some good ones, links ?

Code: Select all

<?
require_once("inc/config.inc");
switch($shownews) 
	{
		case 'default':
		echo '<html><head><title>"'.$site_name.'" News</title></head>';
		echo '<body bgcolor="#EEEEEE" text="#000000">';
		echo '<center><h1>'.$site_name.' News</h1></center>';
		$gd = getdate();
		$filename = "news/news".$gd["mday"]."-".$gd["mon"]."-".$gd["year"].".txt";
		if (!((file_exists($filename)) || is_file($filename) || is_readable($filename)))
			{
			die(":NEWS FILE ERROR::");
			}
		$data=file($filename);
		echo "<table align="center">";
		echo "<tr><td><h1>".$data[0]."</h1></td></tr>";
		echo "<tr><td>";
		for ($i=1;$i<count($data);$i++)
			{
			echo "</table>";
			}
		break;

		case 'write_news':
		echo '<html><head><title>"'.$site_name.'" News</title><head>';
		echo '<body bgcolor="#EEEEEE" text="#000000">';
		echo '<table width="600" border="1" align="center" bordercolor="#000000" cellspacing="0">';
		echo '<tr><td width="300" height="146" bgcolor="#EEEEEE">';
		echo '<form name="write_news" method="post" action="news.php?shownews=write_news.php">';
		echo '<table width="48%" border="0" algin="center">';
		echo '<tr><td><center><b>Add "'.$site_name.'" News</b></center></td></tr>';
		echo '<tr><td><center><input typ="text" name="headline" size="35">';
		echo '</center></td></tr>';
		echo '<tr><td><center><b>Main Article</b></center></td></tr>';
		echo '<center><TEXTAREA NAME="news" ROWS="7" COLS="30"></TEXTAREA></center></td></tr>';
		echo '<tr><td><div align="center">';
		echo '<input type="submit" name="submit" value="submit">';
		echo '</div></td></tr></table></form></td>';
		echo '<td width="300" height="146" bgcolor="#EEEEEE">';
		echo '<form name="old_news" method="post" action="write_admin_news.php">';
		echo '<p align="center">';
		echo '<select name="select"size="1"><option value="0">Old News</option>';
		if (!((file_exists("news")) || (is_dir("news"))))
		{
		mkdir("news",0700);
		}
		else
			{
			$filelist = opendir('news/');
			while($file=readdir($file));
				{
				if (is_file($file))
				{
				echo '<option value="'.$file.'">"'.$file."(".$filetype($file).'")</option>';
				}
			}
		}
		?>
		</select></p>
		<p align="center"><input type="radio" name="radio" value="delete">
		<b>Delete!</b></p>
		<p align="center">
		<input type="submit" name="submit2" value="submit"></p></form></td></tr></table>
		</body></html>
		<?
	break;
	}

?>
FIXED :)

Posted: Tue Jun 15, 2004 7:12 pm
by ol4pr0
infolock wrote:$filelist = opendir('news'/');

should be

$filelist = opendir('news/');

Thanks.. That made this forum show me aswell, rapidly actually

Posted: Tue Jun 15, 2004 7:59 pm
by dull1554
i'd suggest zend studio....bu8t if cash is a problem the best(free) php editor is PHP Coder Pro
http://www.phpide.de

Posted: Wed Jun 16, 2004 2:57 am
by Grim...
I cannot rate TextPad highly enough.

Posted: Wed Jun 16, 2004 9:04 am
by d3ad1ysp0rk
I love winSyntax personally. :)

Posted: Wed Jun 16, 2004 12:20 pm
by feyd
enough threadjacking..

Posted: Wed Jun 16, 2004 12:37 pm
by d3ad1ysp0rk
Feyd:
ol4pr0 wrote:stupid as it is.. this forum made me see my mistake more quickly than my editplus, maby i should use another editor ?

Anybody got some good ones, links ?

Posted: Wed Jun 16, 2004 12:39 pm
by feyd
the link to our already running discussion about editors:

http://www.devnetwork.net/forums/viewtopic.php?t=6288

please use that.

Posted: Wed Jun 16, 2004 3:37 pm
by ol4pr0
Oke i will try some of them editors. thanks.

However i still have a little problem here, in the case 'write_news':

you can only submit 1 news item a day
: Undefined variable: file in
fputs(): supplied argument is not a valid stream resource
fclose(): supplied argument is not a valid stream resource

Code: Select all

case 'news_add':

		echo '<html><head><title>"'.$site_name.'" News</title><head>';
		echo '<body bgcolor="#EEEEEE" text="#000000">';
		echo '<table width="600" border="1" align="center" bordercolor="#000000" cellspacing="0">';
		echo '<tr><td width="300" height="146" bgcolor="#EEEEEE">';
		echo '<form name="write_news" method="post" action="'.$_SERVER['PHP_SELF'].'?shownews=write_news">';
		echo '<table width="48%" border="0" algin="center">';
		echo '<tr><td><center><b>Add "'.$site_name.'" News</b></center></td></tr>';
		echo '<tr><td><center><input typ="text" name="headline" size="35">';
		echo '</center></td></tr>';
		echo '<tr><td><center><b>Main Article</b></center></td></tr>';
		echo '<center><TEXTAREA NAME="news" ROWS="7" COLS="30"></TEXTAREA></center></td></tr>';
		echo '<tr><td><div align="center">';
		echo '<input type="submit" name="submit" value="submit">';
		echo '</div></td></tr></table></form></td>';
		echo '<td width="300" height="146" bgcolor="#EEEEEE">';
		echo '<form name="old_news" method="post" action="old_news.php">';
		echo '<p align="center">';
		echo '<select name="select"size="1"><option value="0">Old News</option>';
		if (!((file_exists("news")) || (is_dir("news"))))
		{
		mkdir("news",0700);
		}
		else
			{
			$filelist = opendir('news/');
			while($file=readdir($file));
				{
				if (is_file($file))
				{
				echo '<option value="'.$file.'">"'.$file."(".$filetype($file).'")</option>';
				}
			}
		}
		echo '</select></p>';
		echo '<p align="center"><input type="radio" name="radio" value="delete">';
		echo '<b>Delete!</b></p>';
		echo '<p align="center">';
		echo '<input type="submit" name="submit" value="submit"></p></form></td></tr></table>';
		echo '</body></html>';
		break;

		case 'write_news':

		if((empty($headline)) || (empty($news)))
		{
		die("$site_name NEWS not complete");
		}
		if (!((file_exists("news")) || (is_dir("news"))))
		{
		mkdir("news",0700);
		}
		$gd=getdate();
		$filename = "news/news".$gd["mday"]."-".$gd["mon"]."-".$gd["year"].".txt";
		if (!((file_exists($filename)) || is_dir("news")))
		{
		$file=fopen($filename,"w+");
		}
		else
		{
		echo 'you can only submit 1 news item a day';
		}

		$headline.='\n';
		$news.='\n';
		fputs($file,$headline); # concerning these 3 lines... 
		fputs($file,$news);
		fclose($file);
		echo '<form name="form" method="post" action="'.$_SERVER['PHP_SELF'].'?shownews=write_news">';
		echo '<table width="48%" border="0" align="center" bgcolor="#EE000E">';
		echo '<tr><td><center><b>Headline</b></center>';
		echo '</td></tr><tr><td><center>';
		echo $headline;
		echo '</center></td></tr><tr><td><center><b>Main Article</b></center>';
		echo '</td></tr><tr><td><center>'; 
		if (!(empty($news)));
		{
		echo $news;
		}
		echo '</center></td></tr><tr><td><div align="center"><a href="main.php">Back to main page</a>';
		echo '</div>';
		echo '</td></tr></table></form></body></html>';
		break;

Posted: Wed Jun 16, 2004 4:25 pm
by feyd
if $filename doesn't exist, or the directory 'news' doesn't exist.. $file will not be created.. move the $file dependant lines and things up into the code where $file is set.. I think that should be fine.

Posted: Wed Jun 16, 2004 5:03 pm
by ol4pr0
But the directory news is being created.

Posted: Wed Jun 16, 2004 8:20 pm
by ol4pr0
if you mean this.

Code: Select all

$file=fopen($filename,"w+");
		$headline.='\n';
		$news.='\n';
		fputs($file,$headline);
		fputs($file,$news);
		fclose($file);
Than yes the error is gone. But no file is created, so the else echo is being returned

Code: Select all

else
		{
		echo 'you can only submit 1 news item a day';
		}
Whats is going wrong ...

Posted: Wed Jun 16, 2004 8:48 pm
by feyd
have you tried deleting today's txt file? .. it appears to only allow the creation of one file per day...