ngreenwood6 Posted October 9, 2007 Share Posted October 9, 2007 I would like to know if anyone can help me create a content management page for my website or if anyone can point me in the right direction. I have a faq page that i would like to edit. Basically i have created a text file in which i have the faq's. I have used the include function to include this file where it is needed. What I would like is a page where i can go that will show me what is in the faq text file and allow me to edit it. This is so that i do not have to open the text file each time i would like to change the content on the site. If anyone can help it is greatly appreciated. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/ Share on other sites More sharing options...
MadTechie Posted October 9, 2007 Share Posted October 9, 2007 basically you need a form to show the data from the text file and to sumit the changes.. heres some examples of reading and writing to a text file fwrite <?php $filename = 'test.txt'; $somecontent = "Add this to the file\n"; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } ?> fread <?php // get contents of a file into a string $filename = "/usr/local/something.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); ?> if you want to go all in, then i would recommend using MySQL, but if its just Static sections then text files are fine.. until you want more Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365755 Share on other sites More sharing options...
ngreenwood6 Posted October 9, 2007 Author Share Posted October 9, 2007 Thank you for your help but i am not very good at coding myself so i need a little more help. Can you write code for a simple html page that will show the data from the text file(name it index.html) Then create a page that will edit the data(edit.html). Then the page that actually changes the data(edit.php), or however you can do it. Your help is greatly appreciated. also create the text file sorry Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365760 Share on other sites More sharing options...
trq Posted October 9, 2007 Share Posted October 9, 2007 I think your missing the point of a help forum. Techie has given you a pretty good example to start with, its up to you to reasearch and code the rest. Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365762 Share on other sites More sharing options...
ngreenwood6 Posted October 9, 2007 Author Share Posted October 9, 2007 yeah i know but i would like to know how to get that data to show up on a form that i can edit. like i said i am a newb and i thought that the point of a forum was to help newbs and i appreciate his help and i think it is up to him to decide whether or not he would like to help Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365765 Share on other sites More sharing options...
MadTechie Posted October 9, 2007 Share Posted October 9, 2007 thorpe, knows me quite well, infact i consider him my superviser friend on this forum, while i am happy to help you must put some work in yourself, creating a form is a HTML issule and not really a PHP one, attempt to create the form and apply the php code, post back any problems you have, starting points <form method="post"> <textarea name="data"> </textarea> <input name="submit" type="submit" /> </form> <?php if(isset($_POST['submit'])) { echo "Data posted:<br />"; echo $_POST['data']; } ?> you just need to glue it all together Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365767 Share on other sites More sharing options...
ngreenwood6 Posted October 9, 2007 Author Share Posted October 9, 2007 so my code would look like this and tell me if this looks good. (faq.html) <html> <body> This is a test! <br> <?php include 'faq.txt'; ?> </body> </html> Then it would be (edit.html) <html> <form action="edit.php" method="post"> <textarea name="data"> </textarea> <input name="submit" type="submit" /> </form> <?php if(isset($_POST['submit'])) { echo "Data posted:<br />"; echo $_POST['data']; } ?> then it would be (edit.php) <?php $filename = 'faq.txt'; $somecontent = "Add this to the file\n"; // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } ?> and then of course i would have my faq.txt file in which this would change. Am i right in how this looks or am i way off. Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365770 Share on other sites More sharing options...
MadTechie Posted October 9, 2007 Share Posted October 9, 2007 personally i would have edit.php as one file, aslo you need to set the new contents (see UPDATE in code) <html> <form action="edit.php" method="post"> <textarea name="data"> </textarea> <input name="submit" type="submit" /> </form> <?php if(isset($_POST['submit'])) { echo "Data posted:<br />"; echo $_POST['data']; $filename = 'faq.txt'; //$somecontent = "Add this to the file\n"; //Get data and set to new contents $somecontent = $_POST['data']; //<---------UPDATED // Let's make sure the file exists and is writable first. if (is_writable($filename)) { // In our example we're opening $filename in append mode. // The file pointer is at the bottom of the file hence // that's where $somecontent will go when we fwrite() it. if (!$handle = fopen($filename, 'a')) { echo "Cannot open file ($filename)"; exit; } // Write $somecontent to our opened file. if (fwrite($handle, $somecontent) === FALSE) { echo "Cannot write to file ($filename)"; exit; } echo "Success, wrote ($somecontent) to file ($filename)"; fclose($handle); } else { echo "The file $filename is not writable"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365783 Share on other sites More sharing options...
sKunKbad Posted October 9, 2007 Share Posted October 9, 2007 I would like to know if anyone can help me create a content management page for my website or if anyone can point me in the right direction. I have a faq page that i would like to edit. Basically i have created a text file in which i have the faq's. I have used the include function to include this file where it is needed. What I would like is a page where i can go that will show me what is in the faq text file and allow me to edit it. This is so that i do not have to open the text file each time i would like to change the content on the site. If anyone can help it is greatly appreciated. Thanks I was working on the same thing last week. Check out this post, it may help you: http://www.phpfreaks.com/forums/index.php/topic,161946.msg708774.html#msg708774 Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365785 Share on other sites More sharing options...
ngreenwood6 Posted October 9, 2007 Author Share Posted October 9, 2007 Thanks for your help mad techie. I will give this a shot and see what happens. My last question is will this show the data in the form that i will be editing from the faq.txt file or do i need to add more code to do that? Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365786 Share on other sites More sharing options...
MadTechie Posted October 9, 2007 Share Posted October 9, 2007 No, your need to use the read from text file code and echo that data into the form Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365790 Share on other sites More sharing options...
ngreenwood6 Posted October 10, 2007 Author Share Posted October 10, 2007 thanks for the info and all your help, but i have no idea how to echo something from php into a form. I will look it up if you do not feel like helping anymore because you helped me out alot and i appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365846 Share on other sites More sharing options...
MadTechie Posted October 10, 2007 Share Posted October 10, 2007 do be trueful, echo'ing is one of the first thing to learn in php <?php echo "Hello World"; ?> add it to a form is the same as adding it to any html file.. please don't take this the wrong way.. but it maybe an idea to get a book or read up on some tutorials, otherwise your just be copying and pasting instead of programming.. jumping in at the deep end works for some people, (myself included) but with PHP, you miss a lot of the stuff that helps later on.. and find yourself having to go back and read the "basics" anyway (but now you wonder why you didn't read them at the start) Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365849 Share on other sites More sharing options...
ngreenwood6 Posted October 10, 2007 Author Share Posted October 10, 2007 I know a little bit. I knew how to echo i just dont know how to properly use it to display text from a text file on a form. If you serisously know of a good book for a beginner at php please let me know and i will read it cause i have been looking for a good one. Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365856 Share on other sites More sharing options...
MadTechie Posted October 10, 2007 Share Posted October 10, 2007 Your need to echo $contents, from the fread (see first post) Oh and I'm an o'reilly fan myself.. so maybe o'reilly PHP cookbook, Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365859 Share on other sites More sharing options...
trq Posted October 10, 2007 Share Posted October 10, 2007 Theres a good book in my signiture. Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365870 Share on other sites More sharing options...
ngreenwood6 Posted October 10, 2007 Author Share Posted October 10, 2007 Thank you all so very much. With all of your help I was able to get it functioning. You are all saints. I will check out both of your links. You are gods to me. Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365936 Share on other sites More sharing options...
prime Posted October 10, 2007 Share Posted October 10, 2007 2 good books that may help you. php and mysql web development by Luke Welling and Laura Thompson and PHP and MySQL for dynamic Web sites by Larry Ullman Quote Link to comment https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/#findComment-365967 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.