AltME: Databases

Messages

Pekr
plese study following link - on the right side, there is a link, of how to process forms using REBOL: http://www.rebol.com/docs/cgi1.html
this is how you should do it - http://www.rebol.com/docs/cgi2.html
afsanehsamim
but in those links ,i can not find database example! i read that link before ,i created html form and cgi as well, it is working properly ... the point is when user enter input and click submit it goes to cgi page. i need save that input in database ...plz guid me or show me one example how can i save value from the form into db?
Pekr
please use:
values: decode-cgi read-cgi
then you will get block of values IIRC
then you pick a value and save it ...
>> blk: decode-cgi "var1=Petr"
== [var1: "Petr"]
>> type? blk
== block!
>> object: construct blk
>> object
>> object/var1
== "Petr"
so use:
values: decode-cgi read-cgi
result: construct values
insert db ["insert into data1(oneone) values(?)" result/oneone]
afsanehsamim
how can i write <input ...> in block?
Pekr
uh, my question is, if you ever worked with CGI?
examples on the above page are pretty straightforward?
there are two things - 1) you have to write a form, basically a html file, with fields, etc., and submit button, linking it to your cgi script 2) you have to write a CGI script, being able to read submitted values ...
I might dig-up some simple example later ...
afsanehsamim
i am using the first one ... can i use codes which you mensioned in above ?  values: decode-cgi read-cgi
result: construct values
insert db ["insert into data1(oneone) values(?)" result/oneone]
afsanehsamim
i wrote whatever you said but i got this error :
>> do %compare.cgi
Script: "Untitled" (none)
Script: "MySQL Protocol" (12-Jul-2008)
MySQL protocol loaded
connecting to: localhost
** Script Error: Invalid path value: oneone
** Where: map-rebol-values
** Near: result/oneone
>>
afsanehsamim
Any one knows how can we save value from the form into database?
Arnold
You first check that the value is acceptable for what can be expected. This is to prevent SQL injections and other malicious input from hackers/innocent users and monkeys using your application. Than you insert a SQL command to insert or update  the mysql database just like you did when you did with your select statement before.
mijnquery: "INSERT INTO cms_artikel (titel, tagregel, sectie, toegevoegd, artikel_tekst) VALUES ('"
mijnquery: append mijnquery rejoin [titel "', '" tagregel "', '" desectie "', '" toegevoegd "', '" artikel-tekst "')"]
insert db mijnquery
The names after INTO are the fieldnames of the table cms_artikel the ones after VALUES are the REBOL variables that get replaced by their values
afsanehsamim
it means i should write like:        query: "INSERT INTO data1 (oneone,onetwo,onethree) VALUES ('"
                                                          query: append insert db rejoin [oneone "', '" onetwo "', '" onethree )"]
                                                           insert db query
i am very thankful if you do based on my codes ...
i am too confiused ...
Arnold
Yes. Do a probe of the query to see if it generates the sql you expected.

Last message posted 106 weeks ago.