[Zope] Simplest example of INSERT

Rob Page rob.page@digicool.com
Wed, 2 Jun 1999 17:17:38 -0400


> > I have a 'dataentry.html' that looks something like this:
> > <form method="post" action="sqltestthing">
> > Color: <input name="col">
> > Flavor: <input name="fla">
> > <input type=submit>
> > </form>
> > 
> > And then a Z SQL Method 'sqltestthing':
> > INSERT INTO TESTTABLE (color,flavor)
> > VALUES (<!--sqlvar col type=nb-->,<!--sqlvar fla type=nb-->)
> > 
> > 
> > I enter the data into the form page, and hit submit. I get back the
> > sqltestthing page saying 'This query requires no input.' I 
> hit submit
> > again, and get 
> > Error, exceptions.SyntaxError: unexpected token sequence.near ::
> > 'lavor)\012VALUES ('*',) 
> 
> 
> I think you mistyped your sqlvar tags - try changing:
> <!--sqlvar col type=nb-->
> to
> <!--#sqlvar col type=nb-->

In general the an SQL Method has little to no useful interface.  Since
you are likely to want to wrap the result (e.g., 'Thanks for
Registering, Daniel') I'd make the target of the form another DTML
document and call the SQLMethod from the second document.  As in:

<form method="post" action="document_wrapper_for_sqltestthing">
Color: <input name="col">
Flavor: <input name="fla">
<input type=submit>
</form>

And then a Z SQL Method 'sqltestthing':
INSERT INTO TESTTABLE (color,flavor)
VALUES (<!--sqlvar col type=nb-->,<!--sqlvar fla type=nb-->)

and THEN a document document_wrapper_for_sqltestthing:

<!--#var standard_html_header-->
<!--#call sqltestthing-->
<P>Thanks for registering your favorite color, <!--#var col--></P>
<!--#var standard_html_footer-->

--Rob