• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r4wp

[Rebol School] REBOL School

Ladislav
10-Nov-2012
[1501]
Still no luck for him, more dependencies needed, I guess. Or maybe 
he really needs Core, not View?
JohnM
12-Nov-2012
[1502]
Hello, all.


 Back in May I was here asking for lots of help in creating a simple 
 CGI script in REBOL. Wanted to say thanks. It was most appreciated, 
 especially considering how rarely you get new people my questions 
 must have seemed so simple to the point of boring the crap out of 
 all of you hardcore experts. My regular job has insane hours and 
 months pass by in what seems like minutes. The person I was doing 
 it for suddenly had other things come up on his website and business 
 that required attention first so it fell by the wayside. I intend 
 to pick it up where I left off this week during an evening when I 
 have more time. While I had a few minutes I had to send my thanks.


 And I see REBOL might become open source... good to see it  moving 
 forward instead of stagnating.
Henrik
12-Nov-2012
[1503]
Welcome back, JohnM!
JohnM
14-Nov-2012
[1504]
Thanks for the welcome back message.
 

 I left off asking about the mySQL driver. So I want to insert into 
 a database a random number the code already generated and associate 
 it with an email address that was provided by a CGI form. Have yet 
 to create this in the real world but for now let us assume I will 
 call the database "customers". The people who process the credit 
 card and collect the email address advised me that the address will 
 be labelled "trnEmailAddress".


 After finding the mySQL driver Here is what I figured out using placeholders 
 for things like password, etc. Would appreicate knowing if this is 
 correct.

; Loads MySQL driver
do %mysql-driver/mysql-protocol.r
; Opens connection to MySQL server
db: open mysql://[[user][:pass]@]host[:port]/database


; Send query to database server. Enters random number from above. 
customers is probably the name of the database I will create

insert db ["INSERT INTO customers VALUES (?,?)" "trnEmailAddress" 
"token"]



 Next I need to insert an existing PDF file (an e-book) into a directory 
 created by the script. The directory will be named after a random 
 number that was earlier generated by the script. I am astounded that 
 I can not find the command to copy a file. So the variable assigned 
 to this random number is called "token".

 So I have the following.

make-dir %token/


 How do I copy a file into this new directory? Also, is that the corecct 
 way to make a directory?
Kaj
14-Nov-2012
[1505]
Use READ and WRITE together
afsanehsamim
16-Nov-2012
[1506]
guys ,i explained my mini project in database and game room ...they 
suggest me this room ! plz help me . my project is about one crossword 
which should show on web page !  i created html form and cgi file 
... when user enter value and press submitt it should save in database 
! my problem is i can not save value from form into database(MYSQL)... 
i am using mysql driver...i can make connectivity and retrieve data 
but i ca not save values ! plz guide me ,i do not have experience 
in REBOL... :(
Andreas
16-Nov-2012
[1507x3]
Please read the CGI documentation suggested to you multiple times.
Basically, you create an HTML file and put it on your webserver. 
Let's call it "form.html":


<form action="form.cgi"><input type="text" name="word"><input type="submit"></form>


Then you create a REBOL CGI matching the "action" used above, so 
"form.cgi", and also put it on your webserver:

#!/usr/local/bin/rebol278 -cs
REBOL []
cgi-values: construct decode-cgi system/options/cgi/query-string


;; Now you can access the "word" value submitted via the HTML form
;; as cgi-values/word.

;; Let's echo the value back to the user, as an example:
print rejoin [
  "Content-type: text/html" crlf
  crlf
  cgi-values/word
]
Instead of echoing the value back to the user, you can do whatever 
you want in the CGI. Such as inserting the value in a database.
Endo
22-Nov-2012
[1510]
Where to use throw-on-error function? How differ from DOing a block?
Ladislav
22-Nov-2012
[1511]
In R2, THROW-ON-ERROR is used for error handling in functions.
BrianH
22-Nov-2012
[1512]
In particular, for error handling in functions with the [catch] attribute.
Ladislav
22-Nov-2012
[1513]
usually as follows:

my-function: func [[catch] x] [throw-on-error [1 / x]]

(notice the [catch] function attribute)
Endo
23-Nov-2012
[1514]
Got it. Thanks a lot.
afsanehsamim
23-Nov-2012
[1515]
@Andreas: i could insert data in database ... now i am comparing 
values which user insreted with correct answers ,i got the result 
of that as well but i want show the result to user on web page ,plz 
tell me what should i do?
Ladislav
23-Nov-2012
[1516]
print ["this is the result:" result]
afsanehsamim
23-Nov-2012
[1517x3]
result is like:[
    ["c" none]
]
[
    ["a" none]
]
[
    ["t" none]
]
[
    ["a" none]
]
[
    ["e" "e"]
]
[
    ["r" none]
]
[
    ["o" "o"]
]
[
    ["a" "a"]
]
i do not want result like this
i want show in neat table
BrianH
23-Nov-2012
[1520]
show
 in this case means formatting your own HTML.
afsanehsamim
23-Nov-2012
[1521x3]
in GUI result should not be like blobks, correct?
you mean i should put my gui sfter print
?
Ladislav
23-Nov-2012
[1524]
then you may need some formatting like:

print "<table>"
foreach row result [print "tr" foreach cell row [print "td" ...

, i.e. print out a HTML table specification
afsanehsamim
23-Nov-2012
[1525]
okkkk
Ladislav
23-Nov-2012
[1526]
err., I meant print "<tr>" in there or print "<td>, etc...
afsanehsamim
23-Nov-2012
[1527x3]
plz tell me how can i use if condition ?
i could get results on web page but there is a problem...in each 
row of table i can see both values(correct and user value )...i want 
use if condition which shows only  the correct result
plzzzzz help
Ladislav
23-Nov-2012
[1530x4]
Example:

    print either a < 0 ["a is small"] ["a is big"]
does that help?
or just

    if a < 0 [print "a is small"]
(otherwise nothing is printed)
afsanehsamim
23-Nov-2012
[1534x2]
i need if condition for situation which two values are same
let me try
Ladislav
23-Nov-2012
[1536]
you mean like this?

    if a =  0 [print "a is zero"]
afsanehsamim
23-Nov-2012
[1537x3]
in my situation what should i write insted of 0?
this is my code:insert db["select data.oneone,data1.oneone from data 
LEFT JOIN data1 ON data.oneone=data1.oneone"]
results: copy db 
if ...
after if what should i write?
Ladislav
23-Nov-2012
[1540]
You have to tell what are you comparing with what.
afsanehsamim
23-Nov-2012
[1541]
i am comparing values of two tables
Ladislav
23-Nov-2012
[1542]
Yes, but you obtained your RESULT. Now, you are processing the RESULT 
block, I assume?
afsanehsamim
23-Nov-2012
[1543x3]
i want to say if they are same print otherwise alert to user
yes
correct
Ladislav
23-Nov-2012
[1546x3]
So, you are doing something like:

foreach record results [
    if first record = second record [...]
]
Is that it?
correcting myself:

foreach record results [
    if (first record) = (second record) [...]
]
afsanehsamim
23-Nov-2012
[1549]
yes ,your right ... :) now if i want send meesage to user that value 
is correct or no ...should i use alert?
Ladislav
23-Nov-2012
[1550]
This is more likely the code you might use:

foreach record results [

    either (first record) = (second record) [print ["they are equal:" 
    first record]] [print ["Alert!"]]
]