A bit of help plz - pretty urgent

Discussion in 'PHP' started by paul_so40, Mar 23, 2009.

  1. #1
    Hi all,

    To start of with ill exsplain what im doing.

    I am making a game walkthrough submitter script.

    How ever i have come across a few things i need some help with doing.

    Ok, so to start of with there are 3 text boxes

    The 1st one they type there username into, the second They write the game title in and 3rd one they add the walkthrough to.

    Then there is a drop down box with 5 selections

    1) Action & Adventure
    2) Driving & Racing
    3) Role-Playing Games
    4) War & Shoot 'Em Ups
    5) Sport

    On submit, it creates a page from a pre made template at walkthrough/templates/file1.html

    wich consists of ( for example )
    <html>
    <head>
    <title>{REPLACE_TITLE}</title>
    </head>
    <body>
    MADE BY <b> {REPLACE_WITH_USERNAME} </b> 
    IN CATAGORY <b> {REPLACE_CATAGORY} </b>
     <b> {REPLACE_DATA} </b>
    </body>
    </html>
    PHP:
    so what i need is to modify the following script to do this, im just not sure on the script to fufill my needs. :( Also i would like it if it gives the file a random name ( so the same one is never used twice )

    <?php
        if(empty($_POST)) {
            ?>
            <form method="post">
               File Name <input type="text" name="name" size="20"><p>
               
                Game Name <input type="text" name="title" size="22"></p>
               <p>
               
                &nbsp;Walkthrough - use as much space as you like<br>
                &nbsp;<textarea rows="16" name="content" cols="51"></textarea><br>
    
                <input type="submit" value="Create"> </p>
            </form>
    <?php
            die();
        }
    
    $name = $_POST['name'];
    $title = $_POST['title'];
    $content = $_POST['content'];
    
    $sanitized_name = preg_replace('/[^0-9a-z\.\_\-]/i','',$name);
    if ($sanitized_name == $name) {
     
            $data = file_get_contents("walkthrough/templates/file1.html");
            if(get_magic_quotes_gpc())
                $data = stripslashes($data);
            $data = str_replace("{REPLACE_TITLE}",$title,$data);           
            $data = str_replace("{REPLACE_DATA}",$content,$data);
           
            write_file("walkthrough/$name.php",$data);
    
    
    
    } else {
      echo "Filename problems.  Try ".$sanitized_name;
      exit;
    } 
    
        function write_file($filename,$data) {
            $f = fopen($filename,"w");
            fwrite($f,$data);
            fclose($f);
        }
    
    
    
    ?>
    PHP:
    also this script creates the script to the folder /walkthrough/ and i would like it to create it into the folder depending on what category they place it under.

    Another thing that would be great ( if anyone knows how to do it ) is to also add a link to the created page, in the form of a table with the text being the game title. ( so its like a menu, that would be great ).

    Any questions just ask

    Thanx - all help is apreceated.

    - Paul
     
    paul_so40, Mar 23, 2009 IP
  2. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #2
    I don't know - is there a reason why you are writing this to files, instead of a database? In my opinion, it would be much much better to use a database for this project, as it will facilitate search and such on the page itself later on. Searching through flat-files is a bore.

    If you select to do this with a database, you would also not have to worry about having subdirectories and such - you could also easily implement a menu based on category, alphabetize the contents of the categories, and you wouldn't really need much more than a single page for displaying them.
     
    PoPSiCLe, Mar 23, 2009 IP
  3. paul_so40

    paul_so40 Peon

    Messages:
    119
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    TBH my php aint all that great, im more of a vb programmer,

    The reason why i am using files is because its the only way i know how to do it. . . i wouldent know how to go about using databases
     
    paul_so40, Mar 24, 2009 IP
  4. snigster

    snigster Peon

    Messages:
    88
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Have a look at this

    http://www.devshed.com/c/a/PHP/Website-Database-Basics-With-PHP-and-MySQL/

    I would definitely recommend you learn how to use MySQL. You will only need the basics to acheive what you wanted above and it's FAR easier in the long run than all this writing to direcotires and creating paths.
     
    snigster, Mar 24, 2009 IP
  5. paul_so40

    paul_so40 Peon

    Messages:
    119
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i havent even been able to learn php yet, so i dont think ill get anywhere with mysql.

    Plz dont think that im one of those peeps that just want everyone to do everything for me, but for this i have no clue on doing what i want and could realy do with a working example to use, and of course learn from.

    I dont mind the fact that its not in a database, but could anyone edit the code to make a working example plz,

    Thanx
     
    paul_so40, Mar 24, 2009 IP
  6. paul_so40

    paul_so40 Peon

    Messages:
    119
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Going back to the OP - anyone know what the script would be ?
     
    paul_so40, Mar 25, 2009 IP
  7. paul_so40

    paul_so40 Peon

    Messages:
    119
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    ?????????????
     
    paul_so40, Mar 26, 2009 IP