Re: Question about creating php files from a form

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 2010-05-13 at 23:07 -0400, Kevin wrote:

> Hello All,
> 
> I am trying to figure out how to create files when a user submits a form ...
> I have seen something about '*fopen*' , is that the direction I should 
> be going?
> 
> Here is what I am trying to accomplish:
> 
> I am creating a program to keep track of recipes for my wife. I have 
> have page set up where she can put the name of the recipe, the 
> ingredients, and the amounts of each ingredient.
> Then she clicks "Submit"
> 
> I would like a html file with the name of the recipe to be created ie 
> *cookies.html  *with a link to the cookies.html created on another page.
> *
> *I hope this makes sense,  and thank you all for your time...
> 
> - - Kevin
> 


It might sound overkill, but I'd use a database for this. All the
recipes can be stored in a MySQL database, and then you can use a simple
couple of queries to produce the recipe list and the recipe pages
dynamically. This also has the advantage that it's very easy to search
the recipe list when it becomes larger, and if you ever want to change
the layout/presentation of the whole system you won't have to recreate
all the recipe pages.

The DB could have several columns labelled: id, name, ingredients,
method

So, the form page (lets assume it's called add.php) could submit to
itself which then adds the recipe to the DB with a query like:

INSERT INTO recipes(name, ingredients, method) VALUES($name,
$ingredients, $method)

This is only a very simple example which could be extended to use
another table for ingredients for a recipe. Don't forget to sanitise any
input coming from the form with mysql_real_escape_string() for inserting
it into the DB.

The list.php page could just use a simple query like:

SELECT id, name FROM recipes

And then create a link to each recipe in the form: recipe.php?recipe=id
(where id is the numerical value used in the DB) and that would then use
a query like:

SELECT * FROM recipe WHERE id=$recipe

MySQL is available on most hosting that you'll find has support for PHP,
and every Linux distribution I've seen has it too.

Thanks,
Ash
http://www.ashleysheridan.co.uk



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux