
March 29th, 2004, 03:09 PM
|
|
|
|
Join Date: Apr 2007
Location: Kirkland, Wa
Posts: 2
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 |
|
|
|
<? if($action == "edit" && isset($HTTP_POST_VARS['password'])) { if($HTTP_POST_VARS['password'] == "<password>") { $line = $HTTP_POST_VARS['date'] . "|" . $HTTP_POST_VARS['name']; $line .= "|" . $HTTP_POST_VARS['news']; $line .= "rn"; $data = file('news.txt'); $data[$id] = $line; $fp = fopen('news.txt', 'w'); foreach($data as $element) { } echo "Item Edited!<BR><BR>n"; echo "<a href="$PHP_SELF">Go Back</a>n"; } else { } } if($action == "edit") { $data = file('news.txt'); $element = trim($data[$id]); echo "Make the changes you would like and press save.<BR>n"; echo "<FORM ACTION="$PHP_SELF?action=edit " METHOD="POST " NAME="editform ">n"; echo "<INPUT TYPE="text " SIZE="30 " NAME="name " value="".$pieces[1].""><BR>n"; echo "<TEXTAREA NAME="news " COLS="40 " ROWS="5 ">". $news. "</TEXTAREA><BR><BR>n"; echo "<INPUT TYPE="password " SIZE="30 " NAME="password "><BR>n"; echo "<INPUT TYPE="hidden " NAME="date" VALUE="".$pieces[0]."">n"; echo "<INPUT TYPE="hidden " NAME="id " VALUE="$id">n"; echo "<INPUT TYPE="submit " NAME="submit " VALUE="Save "><BR>n"; } if($action == "delete" && isset($HTTP_POST_VARS['password'])) { if($HTTP_POST_VARS['password'] == "<password>") { $data = file('news.txt'); $fp = fopen('news.txt', 'w'); foreach($data as $element) { } echo "Item deleted!<BR><BR>n"; echo "<a href="$PHP_SELF">Go Back</a>n"; } else { } } if($action == "delete") { echo "<H2>You are about to delete the following news item.</H2>n"; $data = file('news.txt'); $element = trim($data[$id]); echo $pieces[2] . "<BR>" . "<b>Posted by " . $pieces[1] . " on " . $pieces[0] . "</b>n"; echo "Are you sure you want to delete this news item? If so, enter the password and click on Delete.<BR>n"; echo "<FORM ACTION="$PHP_SELF?action=delete " METHOD="POST " NAME="deleteform ">n"; echo "<INPUT TYPE="password " SIZE="30 " NAME="password "><BR>n"; echo "<INPUT TYPE="hidden " NAME="id " VALUE="$id">n"; echo "<INPUT TYPE="submit " NAME="submit " VALUE="Delete "><BR>n"; } echo "<H1><u>Current News</u></H1>n"; $data = file('news.txt'); foreach($data as $key=>$element) { $element = trim($element); echo $pieces[2] . "<BR>" . "<b>Posted by " . $pieces[1] . " on " . $pieces[0] . "</b>n"; echo " <a href="$PHP_SELF?action=delete&id= $key">Delete</a>n"; echo " <a href="$PHP_SELF?action=edit&id= $key">Edit</a>n"; } echo "<H1><u>Add News</u></H1>n"; if($HTTP_POST_VARS['submit']) { if($HTTP_POST_VARS['password'] == '<password>') { if(!$HTTP_POST_VARS['name']) { echo "You must enter a name"; } if(!$HTTP_POST_VARS['news']) { echo "You must enter some news"; } if(strstr($HTTP_POST_VARS['name'], "|")) { echo "Name cannot contain the pipe symbol - |"; } if(strstr($HTTP_POST_VARS['news'], "|")) { echo "News cannot contain the pipe symbol - |"; } $fp = fopen('news.txt', 'a'); if(!$fp) { echo "Error opening file!"; } $line = date("m.d.y") . "|" . $HTTP_POST_VARS['name']; $line .= "|" . $HTTP_POST_VARS['news']; $line .= "rn"; echo "Error closing file!"; } echo "<b>News added!</b>n"; } else { } } ?> <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>
|