Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/72537-content-management-on-my-website/
Share on other sites

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 ;)

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

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

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

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.

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";
}

}
?>

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

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)

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.