6

I'm making a social network type site, where users can upload their items to be rated. However, I'm trying to improve the way the site is laid out, so want to automatically generate pages once the user inserts a new item. The add.php page has the following form:

<form action="add.php"  method="post"  autocomplete="on" enctype="multipart/form-data" action="<?php echo                  $_SERVER['PHP_SELF']; ?>" method="POST" id="pic">
    <p> <label for="jname" class="iconic user"> Name of Jam <span class="required">*</span></label> <input type="text" name="jname" id="jname" value="<?php if (isset($_POST['jname'])) echo $_POST['jname']; ?>" required="required" placeholder="Input your Name of Jam here"  /> </p>

    <p> <select name="jtype" id="jtype" value="<?php if (isset($_POST['jtype'])) echo $_POST['jtype']; ?>" required="required">
            <option value="jam">Jam</option>
            <option value="jelly">Jelly</option>
            <option value="marmalade">Marmalade</option>
            <option value="preserve">Preserve</option>
        </select> </p>

    <p> <label for="producer" class="iconic user"> Jam Producer <span class="required">*</span></label>     <input type="text" name="producer" id="producer" value="<?php if (isset($_POST['producer'])) echo $_POST['producer']; ?>" required="required" placeholder="Input the producer of the Jam here"  /> </p>
    Upload a picture of your jam: </br> </br> <input name="userfile" type="file" /> </br>
    <input type="submit" name="submit" value="Register" />    
    <input type="hidden" name="submitted" value="TRUE" />

</form>

When the form is submitted, I then want it to generate a new page for that new user created item. Is there a fairly simple way of doing this?

Cheers

Bic1245
  • 127
  • 1
  • 2
  • 12

4 Answers4

8

You don't have to actually 'create' new html page for each item.

You could save this information to database (mysql for example).

Then you could create another php file, say 'item.php' and access different entries from mysql database like so:

item.php?id=1

Sergejs Rižovs
  • 458
  • 1
  • 4
  • 11
  • Okay, so each item in my database gets generated an ID, and I've created an item.php page. How do I then go about associating that id, with the page? The items are listed in 1 page, and then I want to be able to click on one, and it load the new page, with the item with the associated id. Is there a tutorial online I could take a look at do you know? Cheers – Bic1245 Dec 29 '12 at 12:45
  • 1
    There are plenty tutorials available online, you can try googling "php mysql for beginners", but as middaparka suggested I seriously recommend you investing in some book. That way you will be able to learn much faster then by asking questions here :) – Sergejs Rižovs Dec 29 '12 at 12:58
  • a lot of sites is using this technique. then you can display according to id var. so the pages are genreally similar (ex. same layout) but the content is different. – user3522940 Aug 05 '15 at 12:41
4

This generally isn't the way such sites are created. (i.e.: You don't generate the physical pages themselves at the point of form submission.) Instead, you'd usually store the form data in a database and then retrieve/display it based on the URL - either by decoding the URL itself via a "controller" or by using a query string variable such as ?producerid=x. This data would then be used to populate a template.

To be honest, I'd really recommend getting hold of a recent PHP book (as far as database access is concerned, you should be using PDO or MySQLi) or following some online tutorials - whilst it might initially seem like this won't be a meaningful form of progress, its likely to pay substantial dividends in the long run.

John Parker
  • 54,048
  • 11
  • 129
  • 129
3

The best and efficient way to do it is to store the data in a database and retrieve it whenever user clicks on specific item. One thing though, if part of your plan is to make your site accessible by google search engine, you have to generate the individual web pages... because, google is only a web crawler...it cant get into mysql or other databases.

2

Usually there's no new page generation for things like that. You should create a template and load dynamic informations from other sources (such an XML file or a database) to it so that it seems a completely new page.

Just:

  1. See what each item page has in common
  2. Define a template which contains the common code
  3. Retrieve dynamic informations (item infos for example) from a database
  4. Use PHP embedded in HTML to load dynamic HTML

An example:

Facebook does not create a new page per each user registration. There's an HTML template which defines the position of the profile photo, the position and style of the posts, the position and style of the friend list and stuff common to any profile page, and then just load different informations when you call such a page for Mark, Frank, Jeff and so on.

Shoe
  • 74,840
  • 36
  • 166
  • 272