Results 1 to 9 of 9

Thread: File Creation Script Help

  1. #1
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default File Creation Script Help

    Hello, recently I have been working on a simple script that allows you to input data into a form and then creates a .html page with that data on it. I think i have it mostly working, but for some reason there is an error while creating the page. Here is my code:

    Form Page (game_record.php):
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">
    <
    head>
    <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <
    title>Untitled Document</title>
    </
    head>

    <
    body>
    <
    form id="game_records" name="game_recorder" method="post" action="game_process.php">
        
    Page Title:
            <
    br />
                <
    input type="title" name="textfield" />
            <
    br />
            <
    br />
        
    Filename:
            <
    br />
                <
    input type="filename" name="textfield" />
            <
    br />
            <
    br />
        
    Team Names:
            <
    br />
                <
    input name="team1" type="text" />
            <
    br />
                <
    input name="team2" type="text"  />
            <
    br />
            <
    br />
        
    Winning Team:
            <
    br />
                <
    input name="win" type="text"  />
            <
    br />
            <
    br />
        
    Score:
            <
    br />
                <
    input name="score" type="text"  />
            <
    br />
            <
    br />
        
    Game Links:
            <
    br />
                <
    input name="game1" type="text"  />
            <
    br />
                <
    input name="game1" type="text"  />
            <
    br />
                <
    input name="game1" type="text"  />
            <
    br />
            <
    br />
                <
    input type="submit" />
    </
    form>
    </
    body>
    </
    html
    Data Process Page (game_process.php):
    PHP Code:
    <?
    require("includes.php");

    $filename $_REQUEST['filename']; //Get filename

    //Add title
    $title stripslashes($_POST['title']);

    //Add team1
    $team1 stripslashes($_POST['team1']);

    //Add team2
    $team2 stripslashes($_POST['team2']);

    //Add winning team
    $win stripslashes($_POST['win']);

    //Add score
    $score stripslashes($_POST['score']);

    //Add game 1
    $game1 stripslashes($_POST['game1']);

    //Add game 2
    $game2 stripslashes($_POST['game2']);

    //Add game 3
    if($game3 stripslashes($_POST['game3'])) {
        
    $add '

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>'
    .$title.'</title>
    </head>

    <body>
    </b>Game Stats for game with '
    .$team1.' vs '.$team2.'</b>
        <br />
        <br />
            Match Score: '
    .$score.'
        <br />
            Winning Team: '
    .$win.'
        <br />
            Game Links:
                <ul>
                    <li><a href="'
    .$game1.'">'.$game1.'</a></li>
                    <li><a href="'
    .$game2.'">'.$game1.'</a></li>
                    <li><a href="'
    .$game3.'">'.$game3.'</a></li>
                </ul>
    '
    ;

    $game $add;

        
    $file = @fopen($filename"w+");
        @
    fwrite($file$game);
        @
    fclose($file);
        
    $message $success;
        }
    else {
        
    $message $add_error;
        }
    echo
    '
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <meta http-equiv="refresh" content="5;url=game_record.php">
    <title>Status</title>
    </head>

    <body>
    '
    .$message.'
    </body>
    </html>
    '
    ;
    ?>
    I hope that is enough to find the problem, if not just post back saying what you need and I will get that to you ASAP. Thanks

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Whats the error that you get, from looking at the above code, I cannot find anything wrong, but if we had an error message, maybe we could pinpoint the problem. (or even a link to the script would be helpful).
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok, the only error I get is that off the message I defined as the error message if it failed to create the file. The link to the test is: http://www.echo-designes.com/testing...ame_record.php . Hope you can find something

  4. #4
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Make sure that the directory that the file is being written to has writable permissions (777). If it does, try taking the "@" sign of the front of fopen, fwrite, etc to see if you get a PHP error. Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  5. #5
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite View Post
    Make sure that the directory that the file is being written to has writable permissions (777). If it does, try taking the "@" sign of the front of fopen, fwrite, etc to see if you get a PHP error. Hope this helps.
    I made sure the folder had writable permission and had already taken out the @ sign, but still no actual PHP error, just the one i set. Anything else to do?

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    The problem with the code is the HTML page, look at the following and below is the corrections.

    Code:
        Game Links:
            <br />
                <input name="game1" type="text"  />
            <br />
                <input name="game1" type="text"  />
            <br />
                <input name="game1" type="text"  />
    correction:

    Code:
        Game Links:
            <br />
                <input name="game1" type="text"  />
            <br />
                <input name="game2" type="text"  />
            <br />
                <input name="game3" type="text"  />
    After fixing that, it gives the PHP errors:

    Warning: fwrite(): supplied argument is not a valid stream resource in C:\wamp\www\test\game_process.php on line 58

    Warning: fclose(): supplied argument is not a valid stream resource in C:\wamp\www\test\game_process.php on line 59
    success
    I'm currently looking for the reason, and a fix for it. As soon as I get it fixed, I will post the corrected code here and explain the problems.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by thetestingsite View Post
    The problem with the code is the HTML page, look at the following and below is the corrections.

    Code:
        Game Links:
            <br />
                <input name="game1" type="text"  />
            <br />
                <input name="game1" type="text"  />
            <br />
                <input name="game1" type="text"  />
    correction:

    Code:
        Game Links:
            <br />
                <input name="game1" type="text"  />
            <br />
                <input name="game2" type="text"  />
            <br />
                <input name="game3" type="text"  />
    After fixing that, it gives the PHP errors:



    I'm currently looking for the reason, and a fix for it. As soon as I get it fixed, I will post the corrected code here and explain the problems.
    Thanks, I await an idea on fixing it

  8. #8
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I have found the reason why it is not working. And it is all in the HTML code.

    Corrections to your original code are as follows (you will see new additions/corrections in red):

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    <form name="game_recorder" method="post" action="game_process.php">
        Page Title:
            <br />
                <input type="text" name="title" />
            <br />
            <br />
        Filename:
            <br />
                <input type="text" name="filename" />
            <br />
            <br />
        Team Names:
            <br />
                <input name="team1" type="text" />
            <br />
                <input name="team2" type="text"  />
            <br />
            <br />
        Winning Team:
            <br />
                <input name="win" type="text"  />
            <br />
            <br />
        Score:
            <br />
                <input name="score" type="text"  />
            <br />
            <br />
        Game Links:
            <br />
                <input name="game1" type="text"  />
            <br />
                <input name="game2" type="text"  />
            <br />
                <input name="game3" type="text"  />
            <br />
            <br />
                <input type="submit" />
    </form>
    </body>
    </html>
    Sorry it took so long to figure it out, I really need to start paying attention to the HTML first before looking at the PHP. I have tested it and it works perfectly now. Let me know if you still have problems.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  9. #9
    Join Date
    Aug 2006
    Location
    Ohio
    Posts
    266
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks a lot man, i really appreciate it and it works great. Darn little errors : / . O, I have another kinda off topic question. Say I want have the data added to two pages, like one page has the full info, but the other one gets a link to the page added, how would I do that?
    Last edited by Titan85; 12-10-2006 at 05:38 AM.

Bookmarks

Posting Permissions

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