• Help
  • Search
  • Login
  • Register
  • Home

Forum: web design and graphics community

Celestial Star Forum > Web Development > Coding > News script
Pages: [1]
« previous next »
  Print  
Author Topic: News script  (Read 2407 times)
Mr Orange
Incubus
**
Posts: 95



View Profile
News script
« on: July 24, 2005, 06:30:20 PM »

Ok, I don't know more php than include & basic if, so I searched the internet for some newsposting script that doesn't require MySQL or chmodding, and I found one, but the site where I found it put the code in one long row, so it's messed up...  So I tried to sort it out, but I'm not sure if I did it right, and even if I did it doesn't work.. Anyhow, the "sorted" code goes like this:

this is the new add form
Code:
<form action="added.php" method="post">
Anv&auml;ndare: <input type="text" name="username" size="23">
<br/>
L&ouml;senord: <input type="password" name="password" size="23">
<br/>
<br/>
<br/>
Titel: <input type="text" name="title" size="23">
<br/>
Av: <input type="text" name="author" size"23">
<br/>
Nyhet: <textarea name="news" cols="30" rows="3" size="12"></textarea>
<br/>
Avatar (Beh&ouml;vs inte):<input type="text" name="image" size="23">
<br/>
<input type="submit" name="Submit" value="Skicka Nyheten">
</form>


And this is the one I sorted out somewhat

Code:
<META http-equiv="refresh" content="5; url=http://yoursite.com">

<?php
 
$username
="user";
$password="password";
if
&
#40;&#40;$_POST["username"&#93;==$username&#41;&&&#40;$_POST["password"&#93;==$password&#41;&#41;&#123; print "NEWS HAS BEEN POSTED!!"; &#125;
else
&
#123; die &#40;"Username or password was incorrect"&#41;; &#125;

?>


<?php

$da 
= getdate&#40;&#41;; 
$date ="$da[weekday&#93; $da[mday&#93; $da[month&#93; $da[year&#93;";
$thumbnail = "$image";if&#40;$thumbnail == ""&#41; &#123; $text = &#40;"<font face='arial' size='2'> <table width='100%' border='0' cellspacing='0' cellpadding='3'><tr><td width='60' height='60' valign='center'><img src='default avatar goes here'></td><td valign='top'>$title by $author on $date<br/>$news</td></tr></table></font><br/><br/>"&#41;; &#125;
else
&
#123; $text = &#40;"<font face='arial' size='2'> <table width='100%' border='0' cellspacing='0' cellpadding='3'><tr><td width='60' height='60' valign='center'><img src='$image'></td><td valign='top'>$title by $author on $date<br/>$news</td></tr></table></font><br/><br/>"&#41;;
$file = fopen&#40;"news.php", "r"&#41;; $read = fread&#40;$file, filesize&#40;"news.php"&#41;&#41;; fclose&#40;$file&#41;; $blah = fopen&#40;"news.php", "w"&#41;;
$news=stripslashes&#40;$text&#41;; fwrite&#40;$blah, "$text $read"&#41;; fclose &#40;$blah&#41;; print "<meta http-equiv=\"refresh\" content=\"news.php\">";

?>


I'd appriciate help as I really need this on my site so my friend could update as well.
Logged

Ryan
Angeling
*
Posts: 20



View Profile WWW
News script
« Reply #1 on: July 25, 2005, 08:06:02 PM »

Did you try using it? If so, what errors did you get?
Logged

url=http://moonlit-magick.net]Moonlit-Magick.net[/url]
Mr Orange
Incubus
**
Posts: 95



View Profile
News script
« Reply #2 on: July 25, 2005, 09:41:57 PM »

when trying to post, I recieve this:

Code:
Parse error: parse error, unexpected $ in /home/vhosts_111mb/senjiko.111mb.com/added.php on line 24



but as I said, I'm pretty new to php, and don't really know how to fix it :/
Logged

Ryan
Angeling
*
Posts: 20



View Profile WWW
News script
« Reply #3 on: July 26, 2005, 03:51:19 AM »

Umm... Ok, you know this
Code:

   <?php 

$da 
= getdate&#40;&#41;; 
$date ="$da[weekday&#93; $da[mday&#93; $da[month&#93; $da[year&#93;"; 
$thumbnail = "$image";if&#40;$thumbnail == ""&#41; &#123; $text = &#40;"<font face='arial' size='2'> <table width='100%' border='0' cellspacing='0' cellpadding='3'><tr><td width='60' height='60' valign='center'><img src='default avatar goes here'></td><td valign='top'>$title by $author on $date<br/>$news</td></tr></table></font><br/><br/>"&#41;; &#125; 
else 
&
#123; $text = &#40;"<font face='arial' size='2'> <table width='100%' border='0' cellspacing='0' cellpadding='3'><tr><td width='60' height='60' valign='center'><img src='$image'></td><td valign='top'>$title by $author on $date<br/>$news</td></tr></table></font><br/><br/>"&#41;; 
$file = fopen&#40;"news.php", "r"&#41;; $read = fread&#40;$file, filesize&#40;"news.php"&#41;&#41;; fclose&#40;$file&#41;; $blah = fopen&#40;"news.php", "w"&#41;; 
$news=stripslashes&#40;$text&#41;; fwrite&#40;$blah, "$text $read"&#41;; fclose &#40;$blah&#41;; print "<meta http-equiv=\"refresh\" content=\"news.php\">"; 

   
?>


Try changing it to this
Code:
  <?php
$da 
= getdate&#40;&#41;;
$date ="$da[weekday&#93; $da[mday&#93; $da[month&#93; $da[year&#93;";
$thumbnail = "$image";if&#40;$thumbnail == ""&#41; &#123; $text = &#40;"<font face='arial' size='2'> <table width='100%' border='0' cellspacing='0' cellpadding='3'><tr><td width='60' height='60' valign='center'><img src='default avatar goes here'></td><td valign='top'><?php echo "$title"; ?>
by <?php echo "$author"; ?> on <?php echo "$date"; ?><br/><?php echo "$news"; ?></td></tr></table></font><br/><br/>"); }
else
{ $text = ("<font face='arial' size='2'> <table width='100%' border='0' cellspacing='0' cellpadding='3'><tr><td width='60' height='60' valign='center'><img src='<?php echo "$image"; ?>'></td><td valign='top'><?php echo "$title"; ?> by $author on <?php echo "$date"; ?><br/><?php echo "$news"; ?></td></tr></table></font><br/><br/>");
$file = fopen("news.php", "r"); $read = fread($file, filesize("news.php")); fclose($file); $blah = fopen("news.php", "w");
$news=stripslashes($text); fwrite($blah, "$text $read"); fclose ($blah); print "<meta http-equiv=\"refresh\" content=\"news.php\">";
?>



BUT KEEP THE OTHER ONE... Just in case.
Logged

url=http://moonlit-magick.net]Moonlit-Magick.net[/url]
Mr Orange
Incubus
**
Posts: 95



View Profile
News script
« Reply #4 on: July 26, 2005, 08:04:58 AM »

Hmm... Now I got another error :?
Code:

Parse error: parse error, unexpected T_VARIABLE in /home/vhosts_111mb/senjiko.111mb.com/added.php on line 17
Logged

Ryan
Angeling
*
Posts: 20



View Profile WWW
News script
« Reply #5 on: July 27, 2005, 08:59:26 PM »

humm... Ok, thats odd.

Ok well, is there any other files, such as news.php

What is on news.php?
Logged

url=http://moonlit-magick.net]Moonlit-Magick.net[/url]
Mr Orange
Incubus
**
Posts: 95



View Profile
News script
« Reply #6 on: July 29, 2005, 02:23:44 PM »

There's nothing in the news.php file,  as it said at the tutorial to keep it blank.

maybe I messed something else up :? so here's the link to the tutorial:click
Logged

Ryan
Angeling
*
Posts: 20



View Profile WWW
News script
« Reply #7 on: July 31, 2005, 08:04:24 AM »

Ok! There we go, I did the whole tutorial over. It works out fine. I dont know what you did wrong, but yeah! Here we go

added.php
Code:

<?php
$username
="login"; //CHANGE TO USERNAME
$password="password"; //CHANGE TO PASSWORD
if
&
#40;&#40;$_POST["username"&#93;==$username&#41;&&&#40;$_POST["password"&#93;==$password&#41;&#41;
&#123; print "NEWS HAS BEEN POSTED!! <a href='main.php'> View news here </a>"; &#125;
 
else
 &
#123; die &#40;"Username or password was incorrect"&#41;;  &#125; ?>

 <?php $da = getdate&#40;&#41;;
  
$date ="$da[weekday&#93; $da[mday&#93; $da[month&#93; $da[year&#93;";
   
$thumbnail = "$image";
   if&
#40;$thumbnail == ""&#41;
    
&#123; $text = &#40;"
    
<font face='arial' size='2'>
     <
table width='100%' border='0' cellspacing='0' cellpadding='3'>
     <
tr>
     <
td width='60' height='60' valign='center'>
     <
img src='default avater goes here'>
     </
td>
     <
td valign='top'>
     
$title by $author on $date
     
<br>
     
$news
     
</td>
     </
tr>
     </
table>
     </
font>
     <
br><br>
     
"&#41;;
      &#125;
      else
       &#123; $text = &#40;"
       
<font face='arial' size='2'>
        <
table width='100%' border='0' cellspacing='0' cellpadding='3'>
        <
tr>
        <
td width='60' height='60' valign='center'>
        <
img src='$image'>
        </
td>
        <
td valign='top'>
        
$title by $author on $date
        
<br>
        
$news
        
</td>
        </
tr>
        </
table>
        </
font>
        <
br>
        <
br>"&#41;;
         &#125;$file = fopen&#40;"
news.php", "r"&#41;;
           $read = fread&#40;$file, filesize&#40;"
news.php"&#41;&#41;;
           fclose&#40;$file&#41;;
            $blah = fopen&#40;"
news.php", "w"&#41;; //Leave alone look and learn, only edit if you know php
             $news=stripslashes&#40;$text&#41;;
              fwrite&#40;$blah, "
$text, $read"&#41;;
               fclose &#40;$blah&#41;;exit;
                print "
<meta http-equiv="refresh\" content=\"news.php\">"; ?>


add.php
Code:
<form action="added.php" method="post">
 Username: <input type="text" name="username" size="23">
 <br>
 Password: <input type="password" name="password" size="23">
 <br><br><br>Title: <input type="text" name="title" size="23">
 <br>By: <input type="text" name="author" size"23"><br>
 News: <textarea name="news"></textarea></br>
 Avater (optional):<input type="text" name="image" size="23">
 <br>
 <input type="submit" name="Submit" value="Submit News"> </form>



main.php (The place where you want the news to show)
Code:
        <? include("news.php"); ?>


news.php is just blank. Leave it that way. It should work now. If it dont, just post again and Ill try do it again. :D

(Im sorry its not in Swedish (sp?). Is that the language yours was in?)
Logged

url=http://moonlit-magick.net]Moonlit-Magick.net[/url]
Mr Orange
Incubus
**
Posts: 95



View Profile
News script
« Reply #8 on: August 07, 2005, 11:20:17 AM »

thanks alot :D I'll try it out. The language part isn't a problem Smiley
Logged

Mr Orange
Incubus
**
Posts: 95



View Profile
News script
« Reply #9 on: August 08, 2005, 05:54:24 PM »

nope... maybe it's because I'm using a free host Sad but they spport php 4.4.0

anyhow, I got these error messages:

Code:
Warning: fread(): Length parameter must be greater than 0. in /home/roach/public_html/nyu/added.php on line 50

Warning: fopen(news.php): failed to open stream: Permission denied in /home/roach/public_html/nyu/added.php on line 52

Warning: fwrite(): supplied argument is not a valid stream resource in /home/roach/public_html/nyu/added.php on line 54

Warning: fclose(): supplied argument is not a valid stream resource in /home/roach/public_html/nyu/added.php on line 55
Logged

puretaurus21
Guest
News script
« Reply #10 on: August 09, 2005, 02:10:33 AM »

try Chmoding it to 666. Maybe that will work.
Logged
Mr Orange
Incubus
**
Posts: 95



View Profile
News script
« Reply #11 on: August 12, 2005, 05:51:57 PM »

I't didn't say anything in the tut... I chose it because I wouln't have to do stuff like that, I'm lazy  :?
Logged

Melfina
Administrator
Valkyrie Randgris
*****
Posts: 1289



View Profile WWW
News script
« Reply #12 on: August 12, 2005, 06:13:50 PM »

You'll definitely have to chmod the file where the news are stored to get the script working. If it doesn't use mysql, it will use chmoded files instead, there's no other option (apart from making the coding manually!).

That's what the error says: it can't open the file and it can't write into it, because it's not chmoded :P
Logged


MySpace  ~ MySpace Codex ~ Rune Nifelheim
Mr Orange
Incubus
**
Posts: 95



View Profile
News script
« Reply #13 on: August 13, 2005, 04:15:26 AM »

Ok thanks. I guess I'll try do to that then.
Logged

Pages: [1]
  Print  
« previous next »
 
Jump to:  

  • Welcome, Guest
  • Members login
  • Register for free

General

  • General
  • New members
  • Announcements
  • Support / Suggestions

Art boards

  • Creative mediums
  • Requests and offers
  • Tutorials
  • Celestial Star tutorials

Web development

  • Coding
  • Web design
  • Advertisements / affiliation

Off-topic

  • The non-sense
  • Ententainment

Go up
eXTReMe Tracker
  • Valid XHTML
  • Valid CSS
Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC | Seo4Smf v0.2 © Webmaster's Talks
Loading...