|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
news system problem
I am experiencing some problems with my news system. That I built from a tutorial at this site.
<? if($action == "edit" && isset($HTTP_POST_VARS['password'])) { //obviously you should change this password on the next line if($HTTP_POST_VARS['password'] == "*********") { $line .= "|" . $HTTP_POST_VARS['headline']; $line = $HTTP_POST_VARS['date'] . "|" . $HTTP_POST_VARS['name']; $line .= "|" . $HTTP_POST_VARS['news']; $line = str_replace("\r\n","<BR>",$line); $line .= "\r\n"; $data = file('news.txt'); $data = array_reverse($data); $data[$id] = $line; //the next line makes sure the $data array starts at the beginning reset($data); //now we open the file with mode 'w' which truncates the file $fp = fopen('news.txt','w'); foreach($data as $element) { fwrite($fp, $element); } fclose($fp); echo "Item Edited!<BR><BR>\n"; echo "<a href=\"$PHP_SELF\">Go Back</a>\n"; exit; } else { echo "Bad password!\n"; exit; } } if($action == "edit") { $data = file('news.txt'); $data = array_reverse($data); $element = trim($data[$id]); $pieces = explode("|", $element); //the next line is to reverse the process of turning the end of lines into breaking returns $news = str_replace("<BR>","\r\n",$pieces[3]); 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 "Headline:<BR>\n"; echo "<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"headline\" value=\"".$pieces[3]."\"><BR>\n"; echo "Name:<BR>\n"; echo "<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"name\" value=\"".$pieces[1]."\"><BR>\n"; echo "The News:<BR>\n"; echo "<TEXTAREA NAME=\"news\" COLS=\"40\" ROWS=\"5\">".$pieces[2]."</TEXTAREA><BR><BR>\n"; echo "Password:<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"; echo "</FORM>\n"; exit; } if($action == "delete" && isset($HTTP_POST_VARS['password'])) { //obviously you should change this password on the next line if($HTTP_POST_VARS['password'] == "**************") { $data = file('news.txt'); $data = array_reverse($data); array_splice($data,$id,1); //now we open the file with mode 'w' which truncates the file $fp = fopen('news.txt','w'); foreach($data as $element) { fwrite($fp, $element); } fclose($fp); echo "Item deleted!<BR><BR>\n"; echo "<a href=\"$PHP_SELF\">Go Back</a>\n"; exit; } else { echo "Bad password!\n"; exit; } } if($action == "delete") { echo "<H2>You are about to delete the following news item.</H2>\n"; $data = file('news.txt'); $data = array_reverse($data); $element = trim($data[$id]); $pieces = explode("|", $element); echo "<b>" . $pieces[3] . "</b>" . "<BR>" .$pieces[2]."<BR>" . "<i>Posted by " . $pieces[1] . " on " . $pieces[0] . "</i>\n"; echo "<BR><BR>\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 "Password:<BR>\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 "</FORM>\n"; exit; } echo "<H1><u>Current News</u></H1>\n"; $data = file('news.txt'); $data = array_reverse($data); foreach($data as $key=>$element) { $element = trim($element); $pieces = explode("|", $element); echo "<b>" . $pieces[3] . "</b>" . "<BR>" .$pieces[2]."<BR>" . "<i>Posted by " . $pieces[1] . " on " . $pieces[0] . "</i>\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 "<BR><BR>\n"; } echo "<HR>\n"; echo "<H1><u>Add News</u></H1>\n"; if($HTTP_POST_VARS['submit']) { if($HTTP_POST_VARS['password'] == '***********') { if(!$HTTP_POST_VARS['headline']) { echo "You must enter a headline"; exit; } if(!$HTTP_POST_VARS['name']) { echo "You must enter a name"; exit; } if(!$HTTP_POST_VARS['news']) { echo "You must enter some news"; exit; } if(strstr($HTTP_POST_VARS['headline'],"|")) { echo "Headline cannot contain the pipe symbol - |"; exit; } 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 .= "|" . $HTTP_POST_VARS['headline']; $line .= "|" . $HTTP_POST_VARS['id']; $line = str_replace("\r\n","<BR>",$line); $line .= "\r\n"; fwrite($fp, $line); if(!fclose($fp)) { echo "Error closing file!"; exit; } echo "<b>News added!</b>\n"; } else { echo "Bad Password"; } } ?> <FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry"> Headline:<BR> <INPUT TYPE="text" SIZE="30" NAME="headline"><BR> 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> That their is my script. I am having a few problem that are listed below...: 1. After I add an entry, and click refresh on my browser, the entry appears on my current news display, however, if refresh is clicked again, the entry once again appears on my display. This happens endlessly, The same entry continues to appear several times. 2. When I click delete, and i delete a file, it deletes a different file. For example, if i delete the first file, it may delete the last one. 3. I want to alternate row colors in my display, but i do not understadn exactly where to place teh php nor what code should be inputted. 4. If i want to make a "latestnews headlines" section on my website. I have created a display inwhich only the headline, the author and date are presented. Additionally, i would like to have a link set up that would take me to the article. However, i do not see any id's in the news.txt file that the tutorial at this site helped me build. PLZ REPLY AS SOON AS POSSIBLE, and NOTE THE NUMBER OF THE PROBLEM, THAT YOU ARE REPLYING ABOUT...JUST TO MAKE THIS ORDERLY. ![]() |
|
#2
|
|||
|
|||
|
This code is really long and would be better suited in a text file and attached to this post.
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > news system problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|