General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 9th, 2003, 11:26 AM
Vince Vince is offline
LordNitrous
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: England
Posts: 137 Vince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Simple News Script Problems

Hey I am trying to code a news script in PHP and this is what I have done so far - note that it doesn't even post the news onto a text file even though it is Chmoded to 666 and is in all the right directories.

PHP Code:
<html>
<
head><title>News</title></head>
<?
php
// This part checks that the form is submitted, and then validates the password

if($http_post_vars['submit']) {
    if(
$http_post_vars['password'] == 'passes') {
// This part makes sure that you entered a username
        
        
if(!$http_post_vars['name']) {
            echo 
"you must enter a name";
            exit;
        }
// This part checks that you entered the blog entry
        
        
if(!$http_post_vars['news']) {
            echo 
"you must enter some news";
            exit;
        }
/* This part checks that you do not include the pipe symbol because it will ruin the content
   news file */
        
        
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";
    }
}
?>
<form action="<?=$php_self?>" method="post" name="newsentry">
your name:<br>
<input type="text" size="30" name="name"><br>
the news:<br>
<textarea name="news" cols="40" rows="5"></textarea><br><br>
news password:<br>
<input type="password" size="30" name="password"><br>
<input type="submit" name="submit" value="post it!"><br>
</form>
</body>
</html> 


That was "addnews.php and here is the news display page:

PHP Code:
<html>
<
head>
<
title> new document </title>
<
meta name="generator" content="editplus">
<
meta name="author" content="">
<
meta name="keywords" content="">
<
meta name="description" content="">
</
head>

<
body>
<?
php
// this sets the variable for data to the news file

$data file('news.txt');
// this reverses the data so that the newest news is displayed first

$data array_reverse($data);
foreach(
$data as $element) {
    
$element trim($element);
    
$pieces explode("|"$element);
    echo 
$pieces[2] . "<br>" "<b>posted by " $pieces[1] . " on " $pieces[0] . "</b><br><br>";
}
?>  
</body>
</html> 


Could someone please fix and also explain the code and why it wasn't working

Reply With Quote
  #2  
Old May 9th, 2003, 11:32 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
What version php are you running?
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #3  
Old May 9th, 2003, 11:38 AM
Vince Vince is offline
LordNitrous
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: England
Posts: 137 Vince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
http://injurytime.scsuk.net/info.php - Link to PHPInfo I don't know exactly which version of PHP is running. Not the latest one though.

Reply With Quote
  #4  
Old May 9th, 2003, 12:38 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Are you recieving any errors when trying to write to the file?

Reply With Quote
  #5  
Old May 9th, 2003, 01:07 PM
Vince Vince is offline
LordNitrous
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: England
Posts: 137 Vince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
No, absolutely nothing happens when I access the script. here are the pages:

http://injurytime.scsuk.net/addnews.php
http://injurytime.scsuk.net/news.php the password for posting is passes btw

Reply With Quote
  #6  
Old May 9th, 2003, 01:36 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Vars are case sensative - so your vars would be ->
PHP Code:
 $HTTP_POST_VARS  /* and not */ $http_post_vars 

Reply With Quote
  #7  
Old May 10th, 2003, 06:15 AM
Vince Vince is offline
LordNitrous
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: England
Posts: 137 Vince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Thanks, I've changed the code and Ill test it out later

Reply With Quote
  #8  
Old May 10th, 2003, 03:09 PM
Vince Vince is offline
LordNitrous
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Location: England
Posts: 137 Vince User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
I finished the script off and it works now...It writes to the .txt file correctly and Ive made the addnews page a bit prettier. If anyone wants to use it please add me on MSN: injurytime94@hotmail.com

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Simple News Script Problems


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway