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
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Tue Jun 15, 2004 7:02 pm
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;
}
}
?>
Last edited by
ol4pr0 on Wed Jun 16, 2004 3:39 pm, edited 2 times in total.
infolock
DevNet Resident
Posts: 1708 Joined: Wed Sep 25, 2002 7:47 pm
Post
by infolock » Tue Jun 15, 2004 7:04 pm
$filelist = opendir('news'/');
should be
$filelist = opendir('news/');
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Tue Jun 15, 2004 7:11 pm
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
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Tue Jun 15, 2004 7:12 pm
infolock wrote: $filelist = opendir('news'/');
should be
$filelist = opendir('news/');
Thanks.. That made this forum show me aswell, rapidly actually
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Tue Jun 15, 2004 7:59 pm
i'd suggest zend studio....bu8t if cash is a problem the best(free) php editor is PHP Coder Pro
http://www.phpide.de
Grim...
DevNet Resident
Posts: 1445 Joined: Tue May 18, 2004 5:32 am
Location: London, UK
Post
by Grim... » Wed Jun 16, 2004 2:57 am
I cannot rate
TextPad highly enough.
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Wed Jun 16, 2004 9:04 am
I love winSyntax personally.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jun 16, 2004 12:20 pm
enough threadjacking..
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Wed Jun 16, 2004 12:37 pm
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 ?
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Wed Jun 16, 2004 3:37 pm
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;
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jun 16, 2004 4:25 pm
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.
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Wed Jun 16, 2004 5:03 pm
But the directory news is being created.
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Wed Jun 16, 2004 8:20 pm
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 ...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Jun 16, 2004 8:48 pm
have you tried deleting today's txt file? .. it appears to only allow the creation of one file per day...