Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Automatically Generate new pages

Tags:

html

php

dynamic

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

like image 983
Bic1245 Avatar asked Dec 29 '12 12:12

Bic1245


People also ask

How do I create a simple web page using PHP?

First we need to create a basic web page template. This is just a standard web page skeleton. You can give it a name like “pageBuilder.php” or something. You don't have to use PHP for this. You could use another programming language, but for this example we'll keep things simple and do it all in PHP. 2. Add Bootstrap

How to generate a new page from a dynamic information?

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.

How do I add images to a PHP page?

Do the standard thing - make a php file that will take a variable - i.e the image's id, hash, name - whatever, it doesn't matter, just make the page accept a parameter that uniquely identifies the image. Then, in the php, you grab the image and description, title etc and print it onto the html.

How do I generate a form page from a URL?

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.


2 Answers

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

like image 83
Sergejs Rižovs Avatar answered Nov 14 '22 21:11

Sergejs Rižovs


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.

like image 45
John Parker Avatar answered Nov 14 '22 23:11

John Parker