heitml Language Guide
by Keith Oustalet
|
This section will demonstrate how to use the SQL INSERT, DELETE and UPDATE commands from within your heitml applications. All of these operations can be performed within heitml's <dbupdate> Tag. As usual, we'll be working with our SQL guestbook to demonstrate our examples, and we'll start by showing how to add records to it. If you haven't already read about Creating heitml it would be a good idea to do so now, because our first example assumes that the information being added to the guestbook was obtained from the heitml FORM created in that section.
Here is what the code looks like:
<dbupdate>
INSERT INTO guestbook
(Guest_Name, Email, Address, Country, Comment)
VALUES
(<? ff.Guest_Name quoted>,
<? ff.Email quoted>,
<? ff.Address quoted>,
<? ff.Country quoted>,
<? ff.Comment quoted>)
</dbupdate>
|
As you can see, we've used the heitml ?-Tag above to evaluate the contents of the "ff.fieldname" expressions and pass the result along to SQL for insertion into the database. Additionally, we specificed the quoted argument to ensure that the result was treated as a string. The effect is the same as if we had done the following:
<dbupdate>
INSERT INTO guestbook
(Guest_Name, Email, Address, Country, Comment)
VALUES
("Keith Oustalet",
"oustalet@h-e-i.de",
"1812 Madison St., Metairie, LA 70001",
"USA",
"I'll be famous now that my name appears in a
heitml Web Page.")
</dbupdate>
|
Experienced programmers know, however, that this literal method of INSERT-ing records into a file is too specific to be generally useful. Since our the first method accepts input from variables whose values are reassigned each time a user fills out the guestbook FORM and clicks on the pre-defined <Submit> button, it is more flexible and, thus, more practical for real-world applications.
To DELETE a record from an SQL TABLE we could, again, do it by referencing the contents of a variable, or by matching a literal as follows:
By referencing a variable:
<dbupdate>
DELETE FROM guestbook
WHERE
Guest_Name = <? ff.Guest_Name quoted>
</dbupdate>
|
By matching a literal:
<dbupdate>
DELETE FROM guestbook
WHERE
Guest_Name = "John Smith"
</dbupdate>
|
Finally, the syntax of the SQL UPDATE command could be illustrated as follows:
<dbupdate>
UPDATE guestbook
SET Guest_Name = <? ff.Guest_Name quoted>,
Email = <? ff.Email quoted>,
Address = <? ff.Address quoted>
WHERE Guest_Name = <? Old_Guest_Name quoted>
</dbupdate>
|
This page was dynamically generated by
heitml
© 1996-1997 H.E.I. All Rights Reserved
|