- Insert data into db with zope
Hi All, PART1 --------- Good, query a gadfly database (select for example) with the general above way works fine, thanks! The general way to do things is to make a Document the target of the form action. Then have that Document interact with the SQLMethod and return some HTML. PART2 --------- Then, I tried to insert data in my table in the same way. But it seems something miss to me, have you a track? Bye, FR. ================================================= document_id = Insert_from_form ================================================= <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <TITLE>New Card</TITLE> </HEAD> <BODY> <FORM ACTION="insert_total_do" METHOD="POST"> <P>Titre <INPUT TYPE="TEXT" NAME="titre_field" SIZE="25"></P> <P>Type <INPUT TYPE="TEXT" NAME="type_field" SIZE="25"></P> <P><INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Submit"><INPUT TYPE="RESET" NAME="Reset" VALUE="Reset"> </FORM> </BODY> </HTML> ================================================= ================================================= Doc_Query_id = insert_total_do ================================================= <!--#var standard_html_header--> <!--#call "DB.insert_total(REQUEST)"--> OK <!--#var standard_html_footer--> ================================================= SQLmethod_id = insert_total ================================================= insert into seminar (titre,type) values ('<!--#var titre_field-->','<!--#var type_field-->' ================================================= ================================================= ERRRRRRRRRRRROR ================================================= Z SQL Method at /Seminar / DB / insert_total Error, exceptions.KeyError: titre_field SQL used: Could not render the query template! ================================================= François-Régis Chalaoux Bioinformatics Group Synthélabo Biomoléculaire 67080 Strasbourg Cedex FRANCE Tél : 03 88 60 87 14 Fax : 03 88 45 90 70
FR Chalaoux wrote:
(snip)
PART2 --------- Then, I tried to insert data in my table in the same way. But it seems something miss to me, have you a track?
Bye, FR.
================================================= document_id = Insert_from_form ================================================= <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML>
<HEAD>
<TITLE>New Card</TITLE> </HEAD>
<BODY>
<FORM ACTION="insert_total_do" METHOD="POST"> <P>Titre <INPUT TYPE="TEXT" NAME="titre_field" SIZE="25"></P> <P>Type <INPUT TYPE="TEXT" NAME="type_field" SIZE="25"></P>
<P><INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Submit"><INPUT TYPE="RESET" NAME="Reset" VALUE="Reset"> </FORM>
</BODY>
</HTML> =================================================
================================================= Doc_Query_id = insert_total_do ================================================= <!--#var standard_html_header--> <!--#call "DB.insert_total(REQUEST)"--> OK <!--#var standard_html_footer-->
================================================= SQLmethod_id = insert_total ================================================= insert into seminar (titre,type) values ('<!--#var titre_field-->','<!--#var type_field-->'
Note, use sqlvar, not var: <!--#sqlvar titre_field type=string--> If you must use var, at least use the sql_quote attribute to get internal quotes handled correctly: '<!--#var titre_field sql_quote-->'
=================================================
================================================= ERRRRRRRRRRRROR ================================================= Z SQL Method at /Seminar / DB / insert_total
Error, exceptions.KeyError: titre_field
Did you define titre_field and type_field as arguments in the SQL method? Jim -- Jim Fulton mailto:jim@digicool.com Technical Director (540) 371-6909 Python Powered! Digital Creations http://www.digicool.com http://www.python.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
Hi, (snip) Jim Fulton wrote :
Did you define titre_field and type_field as arguments in the SQL method?
No, I missed. I did it and it works fine now but only when my form ACTION is the "insert_total" SQLmethod not with "insert_total_do" document which shoud call the "insert_total" SQLmethod :( In fact I would like to transfert the form data directly in the data base and not use the form display by the SQL method! Bye, FR. François-Régis Chalaoux Bioinformatics Group Synthélabo Biomoléculaire 67080 Strasbourg Cedex FRANCE Tél : 03 88 60 87 14 Fax : 03 88 45 90 70
FR Chalaoux wrote:
Hi,
(snip)
Jim Fulton wrote :
Did you define titre_field and type_field as arguments in the SQL method?
No, I missed. I did it and it works fine now but only when my form ACTION is the "insert_total" SQLmethod not with "insert_total_do" document which shoud call the "insert_total" SQLmethod :(
I find this very surprising and can't reproduce it. Do me a favor, use the option in the "Add" list to add a "Z Search Interface" to add an input form and a report. Based on the query. View and submit the input form and see if that works. If it does, then edit the report to use a call rather than an in and try again.
In fact I would like to transfert the form data directly in the data base and not use the form display by the SQL method!
You don't have to use the SQL method's test form. See if things are any clearer after trying what I suggested above. Jim -- Jim Fulton mailto:jim@digicool.com Technical Director (888) 344-4332 Python Powered! Digital Creations http://www.digicool.com http://www.python.org Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email address may not be added to any commercial mail list with out my permission. Violation of my privacy with advertising or SPAM will result in a suit for a MINIMUM of $500 damages/incident, $1500 for repeats.
participants (3)
-
chalaouxf@synbio.tpgnet.net -
Jim Fulton -
Jim Fulton