Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Regular Coder
    Join Date
    Jan 2010
    Posts
    153
    Thanks
    53
    Thanked 0 Times in 0 Posts

    Page help please

    Hey guys. I was wondering if it's possible to have a page say /admin.php, where I can create new pages from?
    I want to be able to create new pages from another page on my site, like /admin.php
    On that page, I'd have a form for the page's properties, like file name. Could anyone assist me in doing this?
    I'm really new to php and want to get better.

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Yes you can do this, and if you need to edit a file that is back a folder you use ../
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • Users who have thanked masterofollies for this post:

    wincode (01-30-2010)

  • #3
    Regular Coder
    Join Date
    Jan 2010
    Posts
    153
    Thanks
    53
    Thanked 0 Times in 0 Posts
    ohh I see
    so how would I make it so that a page is created?

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    What do you consider a "page" ... not sure what you mean by that.

    Are you talking about creating a text file (for content)?
    Usually, you don't create a "page", as in an HTML or PHP web page ...
    you create the text or content for another script to use ... which generates
    the HTML "page". Typically using a database, like MySQL.

  • Users who have thanked mlseim for this post:

    wincode (01-30-2010)

  • #5
    Regular Coder
    Join Date
    Jan 2010
    Posts
    153
    Thanks
    53
    Thanked 0 Times in 0 Posts
    Yes. Here I'll explain.
    I'm trying to make a site so that I don't have to edit it by uploading files to ftp to make small changes like adding news or links. I'd also like to be able to create a new page.
    Here below is what it would look like.

    Code:
    <html>
    <body bgcolor=FFFFFF>
    
    <a href="http://www.MYSITE.com/home.php">HOME</a> - <a href="http://www.MYSITE.com/news.php">NEWS</a> - <a href="http://www.MYSITE.com/coollinks.php">COOL LINKS</a> - 
    </br>
    
    This is the homepage.
    </body>
    </html>
    I want to have a page, where I can edit what it says in home.php in the part where it says "This is the homepage". The same thing goes for news.php and coollinks.php.

    But I'd also want to be able to add a new page, but I'll do that later when I'm able to do this.

    Thanks a lot for your help.

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    That is called a CMS (content management system).
    Somehow, you either need to use a database (like MySQL),
    or a simpler text (flat-file) database, or at a minimum, some plain text files.

    Let's go with the most basic, plain text files ...

    The first step is to create the text you want and save it in files.
    You might want to do them in sections, like:
    n1.txt, n2.txt, n3.txt for paragraphs of news,
    and l1.txt,l2.txt,l3.txt for paragraphs (or content) for links.

    Create those text files and put text in them (you can also put HTML in them).
    Upload them all into a directory called "content".

    Then, wherever you want them to appear, you do this:
    <?php include("./content/n1.txt")?>

    The PHP script will take the contents of "n1.txt" and display it at that spot.

    Do that for all of your content.

    The next step is to find a simple PHP editor to edit those text files,
    or edit them using notepad and upload them. The PHP editor is something
    you can do later, when you learn more about PHP.

    But the PHP "includes" is the most basic, first step, to putting content on your page,
    without using a database (like MySQL). Eventually, you'll be wanting to get more
    elaborate and learn MySQL.


    .
    Last edited by mlseim; 01-28-2010 at 11:03 PM.

  • Users who have thanked mlseim for this post:

    wincode (01-30-2010)

  • #7
    Regular Coder
    Join Date
    Jan 2010
    Posts
    153
    Thanks
    53
    Thanked 0 Times in 0 Posts
    Ahh perfect. I can do the text files easily. But I would really like to have the editor so that I don't have to edit in notepad and upload.

  • #8
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Database is way more simple than using text files.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #9
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    Database is more simple and more powerful for experienced people,
    but in his case, he'll need to know MySQL and set-up
    variables, and the coding to read and write the database.

    The "point" is ... MySQL is simpler for an experienced programmer.

    Wincode ...
    How far are you planning on going with your site?
    Adding dozens or hundreds of "content" paragraphs?
    Searching, sorting, dating them, etc?

    We can't teach you a whole programming class on this forum,
    so I would say ... you have a start on it, where do you want
    to go from here?

  • Users who have thanked mlseim for this post:

    wincode (01-30-2010)

  • #10
    Regular Coder
    Join Date
    Jan 2010
    Posts
    153
    Thanks
    53
    Thanked 0 Times in 0 Posts
    No I want it very simple.
    I just want 4-5 pages, in which I can update regularly.. I want maybe one master paragraph for each page, where I can change and add to the paragraph (but possibly be able to add links (without coding), images, and file uploading, so in other words a veryy simple editor). But I guess those are complex, so at the moment I just want to be able to add/change text to the pages.

    Thank you so much for your help!

    I think I have an idea of how it would work..
    What I would have is connect to the database and set up a 5 variables (each for a page paragraph). Then on the page where I edit my pages, I would have the editors. And what the editors would do is display what each variable has. Say one of the vairables is $page1, then I can view what's in it and change it/add to it.
    Then on www.mysite.com/page1.php , I'd have an include statement to include the variable $page1.
    But my problem is I don't know how to do it...

  • #11
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    Below is the simplest online text editor ever ... no security, no frills ...

    Make sure all of your text files have CHMOD permissions set to 0777 (or 777),
    using your FTP program ... you can set those permissions, so you can write to them.


    PHP Code:
    <?php
    // Give this script a name like, "edit.php"
    // Very simple text editor.
    // To edit one of your files, call it like this:
    // <a href="edit.php?p=n1.txt">Edit n1.txt</a>

    // There is no error checking, no security,
    // just a plain text editor.

    if(isset($_POST['action'])){
    $action=$_POST['action'];
    }
    if(isset(
    $_POST['textarea'])){
    $textarea=$_POST['textarea'];
    }

    if(isset(
    $_GET['p'])){
    $p=$_GET['p'];
    }

    $url $p;

    // Get page
    $data implode(""file($url)); 

    if(
    $action=="save"){
    $newtext=stripslashes($textarea);
    $newtext str_replace("<?"""$newtext);
    $newtext str_replace("?>"""$newtext);
    $newtext nl2br($newtext);
    $fh fopen($url'w') or die("can't open file");
    fwrite($fh$newtext);
    fclose($fh);
    // where to go after they click "update"
    header ("location: page.php?p=$url");
    }
    else{
    echo
    "
    <html>
    <head><title>Simple Text Editor</title>
    <style>
    body,html{
    margin:0px auto;
    width:700px;
    text-align:center;
    }
    #content{
    margin:0px auto;
    width:700px;
    }
    #middle h1 {
        color: transparent;
        font-family:georgia;
        font-size:12pt;
        margin:0;
        color: #dF9100;
        padding:10px 0px 15px 0px;
        text-align:left;
    }
    </style>
    <body>
    <div id='content'>
    "
    ;

    $ta=br2nl($data);
     
    // where to return to, if they click "return" ...
     
    $return="index.php";
     
    echo
    "
    <a href='$return'><-- Return to Page</a><br /><br />
    Make Changes and click \"Save Changes\" at the very bottom ...<br />
    <form action='edit.php' method='post'>
    <input type='hidden' name='action' value='save'>
    <input type='hidden' name='p' value='$page'>
    <input type='hidden' name='n' value='$n'>
    <textarea name='textarea' rows='25' cols='80'>$ta</textarea>
    <br />
    <input type='submit' name='submit' value='Save Changes'>
    </form>

    <div id='middle' style='width:680px; text-align:left; padding-left:20px; border:1px solid #ccc;'>

    </div>
    </div>
    </body>
    </html>
    "
    ;
    }

    function 
    br2nl($str) {
    return 
    preg_replace('=<br */?>=i'""$str);
    }

    ?>

    .

  • #12
    Regular Coder
    Join Date
    Jan 2010
    Posts
    153
    Thanks
    53
    Thanked 0 Times in 0 Posts
    Ahh great! Thanks a lot (:
    So this isn't database based?

    Also, what does "implode("", file($url))" do?
    I'm getting an error after I click "Save Changes":

    Warning: implode() [function.implode]: Invalid arguments passed in /home/USERNAME/public_html/php/edit.php on line 26
    can't open file


    So I made a txt file and then I chmod it to 777. Then I called it with edit.php?p=
    and then clicked Save Changes, which is when I got the error.

    Hmm, I wish I knew php ):

  • #13
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,531
    Thanks
    8
    Thanked 1,091 Times in 1,082 Posts
    my bad ... I see the error ...

    Change this line:
    <input type='hidden' name='p' value='$page'>

    To this:
    <input type='hidden' name='p' value='$url'>

    ===================

    For all of your PHP questions, there is an online PHP manual for everything:
    http://php.net/manual/en/function.implode.php

    Use Google and search for PHP things using the word "PHP" and then the command:
    Like this: PHP date
    http://www.google.com/search?hl=en&q...=f&aqi=g10&oq=

    The first hit will most likely be the PHP Manual.

  • #14
    Regular Coder
    Join Date
    Jan 2010
    Posts
    153
    Thanks
    53
    Thanked 0 Times in 0 Posts
    Hmm, I'm still getting the same error.

    Also, on the edit.php?p=blahblah, there are two "Save Changes" buttons. In between them is this text ""; } function br2nl($str) { return preg_replace('=
    =i', "", $str); } ?>"

    Thank you so, so much! I really appreciate it! (:

  • #15
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Can you post your coding 5 lines above and 5 lines below that error? or just the whole function? I would like to help tackle this problem.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •