Automatically Create Page

Discussion in 'PHP' started by GLD, Jan 29, 2006.

  1. #1
    Hi there everyone.

    I have a form on my webpage that allows visitors to submit a short piece of text to the site, which is then added to a MySQL database.
    I would like to create/find a script that would automatically create a webpage which would display just that piece of text (ie.: "domain.com/contentid=6546"). I have seen this used on many websites out there and have searched around online but I can't seem to find out how it can be done. Could anyone please point me in the right direction?

    Regards,
    GLD
     
    GLD, Jan 29, 2006 IP
  2. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If it gets stored in MySQL with a unique ID you can (simplified):

    $article_id = $_GET['contentid'];

    SELECT article from your_table WHERE id = $article_id

    Echo $article;
     
    T0PS3O, Jan 29, 2006 IP
  3. GLD

    GLD Well-Known Member

    Messages:
    307
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    140
    #3
    Thanks for the quick reply.

    What I'm actually looking to do though is create a unique webage for each of the users submissions (much like they have at urbandictionary.com, or everything2.com). Every submission will automatically create a page.)
     
    GLD, Jan 29, 2006 IP
  4. themole

    themole Peon

    Messages:
    82
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Do you want an actual file created for each submission or something dynamic that uses one file like the above sites and example?


    -the mole
     
    themole, Jan 29, 2006 IP
  5. GLD

    GLD Well-Known Member

    Messages:
    307
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    140
    #5
    I was actually looking for something dynamic. My post wasn't very clear - sorry about that. :)
    I think T0PS3O's suggestion may have been what I was looking for. I'm trying it now... :)

    EDIT: Here is what I'm using, but it's not working. Could anyone please explain why?

     
    GLD, Jan 29, 2006 IP
  6. themole

    themole Peon

    Messages:
    82
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #6
    name_id is still set to your GET var is probably where you're getting mixed up. Give this a shot:

    
    <html>
    <body>
    
    <?php
    
    // connect to the server
    mysql_connect( 'host', 'user', 'password' )
    or die( "Error! Could not connect to database: " . mysql_error() );
    
    // select the database
    mysql_select_db( 'database' )
    or die( "Error! Could not select the database: " . mysql_error() );
    
    $name_id = $_GET['contentid'];
    
    $query = "SELECT `name` FROM `yourday` WHERE `id` = `$name_id`";
    
    $result= mysql_query( $query );
    
    $row = mysql_fetch_array( $result ); 
    
    $user_submitted_content = stripslashes( $row['name'] );
    
    echo $user_submitted_content;
    
    ?>
    
    </body>
    </html>
    
    Code (markup):
    -the mole
     
    themole, Jan 29, 2006 IP
  7. GLD

    GLD Well-Known Member

    Messages:
    307
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    140
    #7
    Hmm, I get an error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/domain.com/testpage.php on line 20... :(
     
    GLD, Jan 30, 2006 IP
  8. GeorgeB.

    GeorgeB. Notable Member

    Messages:
    5,695
    Likes Received:
    288
    Best Answers:
    0
    Trophy Points:
    280
    #8
    mysql_connect( 'host', 'user', 'password' ) <-- did you change those?

    mysql_select_db( 'database' ) <-- more likely.. did you change this?

    $query = "SELECT `name` FROM `yourday` WHERE `id` = `$name_id`"; <-- MOST likely... are these correct
     
    GeorgeB., Jan 30, 2006 IP
  9. GLD

    GLD Well-Known Member

    Messages:
    307
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    140
    #9
    Yep I changed host, user, password and database. :)

    And yes those are correct. $name_id was defined further up wasn't it?
    Am I supposed to replace the contentid though? ("$name_id = $_GET['contentid']")
     
    GLD, Jan 30, 2006 IP
  10. wwm

    wwm Peon

    Messages:
    308
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #10
    what u can do instead of using databases

    is to write their text into a text file, surroubd it with whatever html tags you want (maybe ur sites logo) and write it to the web directory
     
    wwm, Jan 30, 2006 IP
  11. GeorgeB.

    GeorgeB. Notable Member

    Messages:
    5,695
    Likes Received:
    288
    Best Answers:
    0
    Trophy Points:
    280
    #11
    No contentid should be in the URL.

    With register_globals on http://mysite.com/?contentid=1234 should be fine.

    Try an object fetch instead.
     
    GeorgeB., Jan 30, 2006 IP
  12. GLD

    GLD Well-Known Member

    Messages:
    307
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    140
    #12
    Thanks for all the help guys - I got it working, to some extent.

    <html>
    <body>
    
    <?php
    
    if ( isset($_GET['contentid']) ):
    
    // connect to the server
    mysql_connect( 'host', 'user, 'password' )
    or die( "Error! Could not connect to database: " . mysql_error() );
    
    // select the database
    mysql_select_db( 'database' )
    or die( "Error! Could not select the database: " . mysql_error() );
    
    $query = mysql_query("SELECT * FROM yourday WHERE id=". (int)$_GET['contentid']) or die(mysql_error());
    
    $user_submitted_content = mysql_fetch_object($query);
    $user_submitted_content = $user_submitted_content->name;
    $user_submitted_content = stripslashes( $user_submitted_content );
    
    echo $user_submitted_content;
    
    else:
    
    echo "Default page";
    
    endif;
    
    ?>
    
    </body>
    </html>
    PHP:
    Problem is: I can't figure out how to output more than a single field (eg: name, and other...). How can I do this? :)
     
    GLD, Jan 30, 2006 IP
  13. GLD

    GLD Well-Known Member

    Messages:
    307
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    140
    #13
    Nobody? :)
     
    GLD, Jan 31, 2006 IP
  14. GeorgeB.

    GeorgeB. Notable Member

    Messages:
    5,695
    Likes Received:
    288
    Best Answers:
    0
    Trophy Points:
    280
    #14
    This line is the key: $user_submitted_content = $user_submitted_content->name;

    Since you have your query set to SELECT * (Meaning ALL)

    Just do something like

    $user_submitted_content1= $user_submitted_content->name;
    $user_submitted_content2 = $user_submitted_content->address;
    $user_submitted_content3= $user_submitted_content->phone;
    $user_submitted_content4 = $user_submitted_content->zip;

    And echo them accordingly
     
    GeorgeB., Jan 31, 2006 IP
  15. GLD

    GLD Well-Known Member

    Messages:
    307
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    140
    #15
    I've tried this but it doesn't seem to work - it doesn't bring up any text other than the name...
     
    GLD, Jan 31, 2006 IP
  16. neterslandreau

    neterslandreau Peon

    Messages:
    279
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #16
    That's because you are trying to assign the same variable diferent values. Only the last assignment will stick.
     
    neterslandreau, Feb 2, 2006 IP
  17. GLD

    GLD Well-Known Member

    Messages:
    307
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    140
    #17
    So what should I do?
    This?
    Doesn't seem to work...
    I've tried litterally every possible combination.
     
    GLD, Feb 2, 2006 IP