Just been spending a bit more time learning php and on the future recipe section for my chance1234.com site. I wanted a clean and simple INSERT INTO example which I can use as a basis for future development.
In the php book I am reading I have tons of examples and on the web, there are tons of examples - but!! A lot of them have lots of other bits and pieces cluttering them up. In good time, as I learn more I am sure it will begin to make sense. But, I think a lot of people who write tutorials forget who they are writing for. Putitng in ISSET() might be second nature for yourself, but if you do not explain why you are putting it there, then it is just confusion.
Also, Yes sometimes the most simple solutions are not the right solution, but for someone learning, stripping back to the essentials can be most beneficial so they can see clearly what is going on. Remember making mistakes is one of the best ways of learning.
Anyway, end of rant and onto my insert.
I have a php file for adding recipes to my database. It currently looks something like this and is tentatively named add.php
<form action="transRecipe.php" method="POST">
<input type="text" size=50 name="recipeTitle" maxlength="255" value="">
<?php listRecipesTypes(); ?>
<textarea name="recipeQuick" rows="6" cols="63"></textarea>
<?php listIngredients() ?>
<input type="submit" type="submit" value="Add Recipe">
I also have a second php file called transRecipes.php , which contains my INSERT INTO code and that looks like this.
$sql = "INSERT INTO recipe (rType,title,quick)
die('Error: ' . mysql_error());
echo "Here is my bottom";
And here is a list of the important condsiderations
- In the form action part , there is the reference to the transRecipe.php file , which you need for it to work
- The $POST[...] parts in transRecipe refer to the names of the input controls on the Add.php file
- The echo parts are there to help me debug and allow us to concentrate on getting the SQL right in the INSERT statement