Tutorial
|
|||
|
Adding a data input form.
In the previous tutorial you created a database table and a page allowing you to view the table contents. The table had no data in it though so your next step will be to create a mechanism to input data to the table. Web pages that manage content stored in database tables usually follow a pretty standard format. In the HTML there is some kind of form or link to pass the data you wish to manage and at the top of the page before the HTML is created there is a piece of code which makes a decision based on the form input and runs SQL code acording to that decision. In this case you are only creating one function, to add data to a table, so we will do it using the TT Web Site Manager's built in conditional items. These allow decisions to be made based on form input with very little coding involved. However they suffer from the disadvantage that when a lot of options are required the page can have a large number of items. In these cases a single PHP item with a PHP SWITCH and PHP code to run the SQL commands provides a tidier solution. The first step is to create the HTML form we'll use to input our data.
To process the form input you'll need a conditional item. Conditional items contain the code you'd put between the brackets in a PHP if() conditional. Form inputs are made available as PHP variables.
To follow the conditional block you'll need a conditional end item. You should only need to create one of these and re-use it again and again within your sites because it contains no code.
The conditional block has to enclose some code to run if the condition evaluates to true so your next step is to create the SQL item containing the insert statement to put your form input into the database.
You must now put the items into the page. The conditional block with the SQL code goes at the top of the page while the data input form goes down in the HTML.
You should now be able to view the page and enter data into the form.
And when you click on the "Save" button the data should appear in the table below.
Of course, this is a very simple database example. In practice you would want to be able to update and delete database items as well as simply insert them. To add update and delete statements would be merely a case of expanding the conditional code at the top of the page, either by using a PHP item or further conditional items, and adding the relevant form inputs in the page HTML. For further inspiration now that you have a basic grounding in the TT Web Site Manager's operation, please look at the demo site shipped with the TT Web Site Manager distribution.
|
|||
|