BorderC Posted January 7, 2007 Share Posted January 7, 2007 It's been a long time since I used php and I lost my book on it. So, here's what I need to do. It's really simple but I forget how.I want to have a page where someone can go and fill out a form, and have the form write to a file that I can then include (SSI) on another page. This way other admins of my site can put in their name and write "news" for the main page of my site and have it automatically display on the main page. And I want the new news to be written to the top of the file to be included, so it shows up as the most recent post. I've done it before but like I said it has been a long time. like 6 years and I totally forget how to do it and cant find my book :( Link to comment https://forums.phpfreaks.com/topic/33238-trying-to-make-a-simple-script-but-need-help/ Share on other sites More sharing options...
scott212 Posted January 7, 2007 Share Posted January 7, 2007 Not really sure what SSI is...But the rest isn't too difficult: 1. Get the data from the form with $_GET['blah'] or $_POST['poo'] and do any form validation you may want.2. writing: $pathToFile = "/news.dat"; $handle = fopen($pathToFile, 'a'); // opens the file for appending $content = "write me"; // clear your data of line breaks and line ends. (I usually replace it with ":::" or something so I can replace them later) fwrite($handle, $content); // write to the file fclose($handle);3. reading: $handle = fopen($pathToFile, 'r'); $entries = file($handle); // reads the file into an array, indexed by new lines $entries = array_reverse($entries); // reverse the array so new entries appear first fclose($handle);4. iterate over the array however you want to display the contents.Is this what you wanted to do? I would recommend looking at http://www.tizag.com/phpT/fileread.php for more help Link to comment https://forums.phpfreaks.com/topic/33238-trying-to-make-a-simple-script-but-need-help/#findComment-155174 Share on other sites More sharing options...
papaface Posted January 7, 2007 Share Posted January 7, 2007 SSI = server side include Link to comment https://forums.phpfreaks.com/topic/33238-trying-to-make-a-simple-script-but-need-help/#findComment-155178 Share on other sites More sharing options...
magic2goodil Posted January 7, 2007 Share Posted January 7, 2007 perhaps a better approach would be to make a mysql database for your news...stores the date, the news, and who posted it...that way you would be more efficient i believe. Link to comment https://forums.phpfreaks.com/topic/33238-trying-to-make-a-simple-script-but-need-help/#findComment-155179 Share on other sites More sharing options...
BorderC Posted January 7, 2007 Author Share Posted January 7, 2007 Yeah, I think you're right, Magic. Now I'll just have to remember how to do that too. If I only had my book lol. guess I should buy another :( Link to comment https://forums.phpfreaks.com/topic/33238-trying-to-make-a-simple-script-but-need-help/#findComment-155196 Share on other sites More sharing options...
scott212 Posted January 7, 2007 Share Posted January 7, 2007 well you obviously have the internet... Never seen a bigger book! ;D Link to comment https://forums.phpfreaks.com/topic/33238-trying-to-make-a-simple-script-but-need-help/#findComment-155199 Share on other sites More sharing options...
BorderC Posted January 7, 2007 Author Share Posted January 7, 2007 Yes, but the book I had covered everything and was easy to understand. Well, not everything, but most of the basics which is all I need. It was called "PHP Essentials". I'm going to try what you suggested too Scott. Link to comment https://forums.phpfreaks.com/topic/33238-trying-to-make-a-simple-script-but-need-help/#findComment-155202 Share on other sites More sharing options...
magic2goodil Posted January 7, 2007 Share Posted January 7, 2007 If you get ambitious, I would suggest the mysql db..as scott said, internet = biiiggg book, lol Link to comment https://forums.phpfreaks.com/topic/33238-trying-to-make-a-simple-script-but-need-help/#findComment-155210 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.