|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Updating Text Files with PHP
I have a news script that updates a dat file through a form, enabling a web site owner to add news articles to their site.
However I would also like them to be be able to delete (and maybe edit) any articles they post. The script seems very basic... <? if($_POST["do"]=="addnew") { $fp=fopen("news.dat","a"); $formatted=ereg_replace("\r\n","<br>",$_POST["news"]); $formatted=ereg_replace("\n","<br>",$formatted); $newsto=date("d M Y")."%~#".$_POST["title"]."%~#".$formatted." \n"; fwrite($fp,StripSlashes($newsto)); fclose($fp); echo " News Article added successfully."; } ?> (the form) <form name="form1" action="<?echo $_SERVER['PHP_SELF']?>" method=post> <p align="left"><?echo date("d M Y");?></p> </form> <form name="form1" method="post" action="<?echo $_SERVER['PHP_SELF']?>"> <p align="center">Title : <input type="text" name="title" size="35" style="border-style utset;"></p> </form> <form name="form1" action="<?echo $_SERVER['PHP_SELF']?>" method=post> <p align="center"> <textarea name="news" rows="13" cols="39" style="border-style utset;"></textarea></p> <p align="center"> <input type="submit" name="formbutton1" value="Add News" style="border-style utset;"><br> </p> <input type="hidden" name="do" value="addnew"> </form> ----------------------------------------------------------------------------------- Can someone show me how to create two new versions of this form - one for editing and one for deleting. |
|
#2
|
|||
|
|||
|
A simple link or image would allow you to embed the href that you need.
I notice you evaluate $_POST["do"]=="... Try adding $_GET["delete"]==1 or something similar from a link or image href, evaluate that first, and if true, then the user wants to use the delete function. It shouldn't be too much harder than that.
__________________
__________________________________________________ _ Wil Moore III, MCP | Integrations Specialist | Senior Consultant Are You Listed...? | DigitallySmooth Inc. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Updating Text Files with PHP |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|