Tutorials
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOtherTutorials

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers 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 March 29th, 2004, 03:09 PM
zipperlip zipperlip is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Kirkland, Wa
Posts: 2 zipperlip User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
News System Part 2 (Edit/Delete Function Not Working)

I have been looking through the code and I cannot find 2 things.

1) The script does not allow editing or deleting of the data file.

I copied the code as it is on the site (thank you Matt), and everything but edit/delete works fine.

If you can help, I would REALLY appreciate it!

php Code:
Original - php Code
  1.  
  2. <?
  3. if($action == "edit" && isset($HTTP_POST_VARS['password'])) {
  4.     if($HTTP_POST_VARS['password'] == "<password>") {
  5.         $line = $HTTP_POST_VARS['date'] . "|" . $HTTP_POST_VARS['name'];
  6.         $line .= "|" . $HTTP_POST_VARS['news'];
  7.         $line = str_replace("rn","<BR>",$line);
  8.         $line .= "rn";
  9.         $data = file('news.txt');
  10.         $data[$id] = $line;
  11.         reset($data);
  12.         $fp = fopen('news.txt','w');
  13.         foreach($data as $element) {
  14.             fwrite($fp, $element);
  15.         }
  16.         fclose($fp);
  17.         echo "Item Edited!<BR><BR>n";
  18.         echo "<a href="$PHP_SELF">Go Back</a>n";
  19.         exit;
  20.     } else {
  21.         echo "Bad password!n";
  22.         exit;
  23.     }
  24. }
  25. if($action == "edit") {
  26.     $data = file('news.txt');
  27.     $element = trim($data[$id]);
  28.     $pieces = explode("|", $element);
  29.     $news = str_replace("<BR>","rn",$pieces[2]);
  30.     echo "Make the changes you would like and press save.<BR>n";
  31.     echo "<FORM ACTION="$PHP_SELF?action=edit" METHOD="POST" NAME="editform">n";
  32.     echo "Name:<BR>n";
  33.     echo "<INPUT TYPE="text" SIZE="30" NAME="name" value="".$pieces[1].""><BR>n";
  34.     echo "The News:<BR>n";
  35.     echo "<TEXTAREA NAME="news" COLS="40" ROWS="5">".$news."</TEXTAREA><BR><BR>n";
  36.     echo "Password:<BR>n";
  37.     echo "<INPUT TYPE="password" SIZE="30" NAME="password"><BR>n";
  38.     echo "<INPUT TYPE="hidden" NAME="date" VALUE="".$pieces[0]."">n";
  39.     echo "<INPUT TYPE="hidden" NAME="id" VALUE="$id">n";
  40.     echo "<INPUT TYPE="submit" NAME="submit" VALUE="Save"><BR>n";
  41.     echo "</FORM>n";
  42.     exit;
  43. }
  44. if($action == "delete" && isset($HTTP_POST_VARS['password'])) {
  45.     if($HTTP_POST_VARS['password'] == "<password>") {
  46.         $data = file('news.txt');
  47.         array_splice($data,$id,1);
  48.         $fp = fopen('news.txt','w');
  49.         foreach($data as $element) {
  50.             fwrite($fp, $element);
  51.         }
  52.         fclose($fp);   
  53.         echo "Item deleted!<BR><BR>n";   
  54.         echo "<a href="$PHP_SELF">Go Back</a>n";
  55.         exit;
  56.     } else {
  57.         echo "Bad password!n";
  58.         exit;
  59.     }
  60. }
  61. if($action == "delete") {
  62.     echo "<H2>You are about to delete the following news item.</H2>n";
  63.     $data = file('news.txt');
  64.     $element = trim($data[$id]);
  65.     $pieces = explode("|", $element);
  66.     echo $pieces[2] . "<BR>" . "<b>Posted by " . $pieces[1] . " on " . $pieces[0] . "</b>n";
  67.     echo "<BR><BR>n";
  68.     echo "Are you sure you want to delete this news item? If so, enter the password and click on Delete.<BR>n";
  69.     echo "<FORM ACTION="$PHP_SELF?action=delete" METHOD="POST" NAME="deleteform">n";
  70.     echo "Password:<BR>n";
  71.     echo "<INPUT TYPE="password" SIZE="30" NAME="password"><BR>n";
  72.     echo "<INPUT TYPE="hidden" NAME="id" VALUE="$id">n";
  73.     echo "<INPUT TYPE="submit" NAME="submit" VALUE="Delete"><BR>n";
  74.     echo "</FORM>n";
  75.     exit;
  76. }
  77.  
  78.  
  79. echo "<H1><u>Current News</u></H1>n";
  80. $data = file('news.txt');
  81. $data = array_reverse($data);
  82. foreach($data as $key=>$element) {
  83.     $element = trim($element);
  84.     $pieces = explode("|", $element);
  85.     echo $pieces[2] . "<BR>" . "<b>Posted by " . $pieces[1] . " on " . $pieces[0] . "</b>n";
  86.     echo "&nbsp;<a href="$PHP_SELF?action=delete&id=$key">Delete</a>n";
  87.     echo "&nbsp;<a href="$PHP_SELF?action=edit&id=$key">Edit</a>n";
  88.     echo "<BR><BR>n";
  89. }
  90. echo "<HR>n";
  91. echo "<H1><u>Add News</u></H1>n";
  92. if($HTTP_POST_VARS['submit']) {
  93.     if($HTTP_POST_VARS['password'] == '<password>') {
  94.         if(!$HTTP_POST_VARS['name']) {
  95.             echo "You must enter a name";
  96.             exit;
  97.         }
  98.         if(!$HTTP_POST_VARS['news']) {
  99.             echo "You must enter some news";
  100.             exit;
  101.         }
  102.         if(strstr($HTTP_POST_VARS['name'],"|")) {
  103.             echo "Name cannot contain the pipe symbol - |";
  104.             exit;
  105.         }
  106.         if(strstr($HTTP_POST_VARS['news'],"|")) {
  107.             echo "News cannot contain the pipe symbol - |";
  108.             exit;
  109.         }
  110.         $fp = fopen('news.txt','a');
  111.         if(!$fp) {
  112.             echo "Error opening file!";
  113.             exit;
  114.         }
  115.         $line = date("m.d.y") . "|" . $HTTP_POST_VARS['name'];
  116.         $line .= "|" . $HTTP_POST_VARS['news'];
  117.         $line = str_replace("rn","<BR>",$line);
  118.         $line .= "rn";
  119.         fwrite($fp, $line);
  120.         if(!fclose($fp)) {
  121.             echo "Error closing file!";
  122.             exit;
  123.         }
  124.         echo "<b>News added!</b>n";   
  125.     } else {
  126.         echo "Bad Password";
  127.     }
  128. }
  129.  
  130. ?>
  131. <FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">
  132. Your name:<BR>
  133. <INPUT TYPE="text" SIZE="30" NAME="name"><BR>
  134. The News:<BR>
  135. <TEXTAREA NAME="news" COLS="40" ROWS="5"></TEXTAREA><BR><BR>
  136. News Password:<BR>
  137. <INPUT TYPE="password" SIZE="30" NAME="password"><BR>
  138. <INPUT TYPE="submit" NAME="submit" VALUE="Post it!"><BR>
  139. </FORM>

Reply With Quote
  #2  
Old March 30th, 2004, 12:13 AM
System System is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Posts: 665 System User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Message Moved

Thread moved from 'PHP Coding' to 'Tutorials' by sliver.

Reason:

Reply With Quote
  #3  
Old March 30th, 2004, 06:52 PM
The Squirrel The Squirrel is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Mid-Indiana, USA
Posts: 153 The Squirrel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Send a message via ICQ to The Squirrel
RE: Message Moved

Is register globals turned on or off in your PHP.ini file?

Have you tried changing all the $HTTP_POST_VARS to just $_POST? Try this and come back if it still does not work. I know this was a problem when I first started working on a similar script.

The Squirrel

Reply With Quote
Reply

Viewing: Codewalkers ForumsOtherTutorials > News System Part 2 (Edit/Delete Function Not Working)


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 |