Ashley Sheridan wrote:
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
Thank you Ash for the quick reply.
I was actually looking at using a database too... and I am testing out a
few different ones (SQLite and MySQL)
I appreciate the extra information, it will be helpful in the future :-)
/On a side note:
I am having some issues with connecting to a SQLite database right now
... I'm getting the following error "Fatal Error: 'sqlite_open' is an
unknown function"
But I'm putting that on the side right now.
/I wanted to try a different approach by just creating the recipes in
individual html files for the time being.
Do happen to know how to create html files from a php form?
Thank you.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php