Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Help!! Apple Script web CGI

Help!! Apple Script web CGI
Thread Tools
Fresh-Faced Recruit
Join Date: Dec 1999
Location: Lincoln, MA USA
Status: Offline
Reply With Quote
May 5, 2000, 09:34 PM
 
Could some one please help me. I am trying to write a cgi that will take a few very simple lines of data store it to a file and compare some things. This is for a school online auction. The way the script should work is that it gets the persons info and bid. Then compares the bid to see if it is the highest bid. If it is, it will put that at the end of the text doc. As of now, all it does when called by the browser is run and quit. No result. In about 30 seconods the browser returns a CGI error. Does any body see an error???

It also sends a conformation e-mail, but I dont have to if that is what is screwing the script up.

--------------------------------

property crlf : (ASCII character 13) & (ASCII character 10)
property null : (ASCII character 0)
property lf : (ASCII character 10)
property pToUser : "travisres@mediaone.net"
--this builds the normal HTTP header for regular access
property http_10_header : "HTTP/1.0 200 OK" & crlf & "Server: MacHTTP" & crlf & ¬
"MIME-Version: 1.0" & crlf & "Content-type: text/html" & crlf & crlf

on handle CGI request path_args ¬
with posted data post_args using access method method
--This is WEIRD syntax. What it really means is that you have the variables
-- path_args, http_search_args, client_address, username, password, etc. to play with.
-- They are all strings.

try --wrap the whole script in an error handler
set formData to parse CGI arguments post_args



set msg to "Your Bid has Been Placed" & ¬
(current date) & return & "Field Values: " & return & return

set email to CGI field "email" from formData
set firstname to CGI field "first" from formData
set lastname to CGI field "last" from formData
set phone to CGI field "phone" from formData
set theBid to CGI field "bid" from formData
set fileNumber to open for access file "bids" with write permission
set bidError to false

if get eof (fileNumber < 1) then

set theText to firstname & null & lastname & null & phone & null & email & null & bid & return
write theText to fileNumber starting at 0

else
set maxBid to 0
try
read fileNumber until null
read fileNumber until null
read fileNumber until null
read fileNumber until null
set bid to read fileNumber before return
if maxBid < bid then
maxBid = bid
end if

end try
set theText to firstname & null & lastname & null & phone & null & email & null & bid & return
write theText to fileNumber starting at (get eof fileNumber)
set bidError to (bid < maxBid)

end if

if bidError then
error "Your Bid Amount was less that the highest bid" number -666
end if

try
set msg to "Dear " & firstname & " " & lastname & "," & return ¬
& "Your bid has been placed for $" & theBid & ". Thank you. Please e-mail travisres@mediaone with any further questions"
tell application "Mondo Mail Pro"

send mail msg subject ("Confirmation on your Bid") to email from ¬
"travisres@mediaone.net" SMTP gateway "smtp.ne.mediaone.net"
end tell
on error emsg number num --report the error message and number to the WWW client
return http_10_header & "Mondomail Error " & num & ", " & emsg
end try

return http_10_header & "<BODY BGCOLOR=#FFFFFF><H1>Thank you! Your bid has been confimed."
on error emsg number num --report the error message and number to the WWW client
return http_10_header & "Error " & num & ", " & emsg
end try
end handle CGI request

--------------------------------
The simple HTML that I am using to test the script is:
<HTML>

<HEAD>
<TITLE>Place Bid</TITLE>

</HEAD>
<BODY BGCOLOR="#FFFFFF">
<P><FORM ACTION="/cgi-bin/bid2.cgi" METHOD=POST>
<P>First<INPUT TYPE=text NAME=first VALUE="" SIZE=30></P>

<P>Last<INPUT TYPE=text NAME=last VALUE="" SIZE=30></P>

<P>Phone<INPUT TYPE=text NAME=phone VALUE="" SIZE=30></P>

<P>e-mail<INPUT TYPE=text NAME=email VALUE="" SIZE=30></P>

<P>bid $<INPUT TYPE=text NAME=bid VALUE="" SIZE=30></P>

<P><INPUT TYPE=submit NAME=Submit VALUE="Submit">
</FORM></P>
</BODY>
</HTML>

Does anybody see any thing wrong???

Also, this script requires Parce CGI OSAX(Parse CGI 1.2) Scripting addition I believe.

Thanks!




[This message has been edited by travisres (edited 05-05-2000).]
     
Dedicated MacNNer
Join Date: Nov 1999
Location: Georgetown, Demerara, Guyana
Status: Offline
Reply With Quote
May 6, 2000, 11:50 PM
 
Hi,

I'm not certain about all the requirements for CGI scripts... One issue that does come to mind is that when you save a CGI script as an applet, it may be necessary to save it with the 'Stay Open' option to avoid prematurely quitting before the CGI Apple Event is actually received (some web servers such as WebSTAR also have other requirements). Also, as you suggested, you could try not sending the email confirmation, to see if that's somehow interfering with the CGI script.

BTW, StarNine has some general tips on AppleScript CGIs in the Developing CGIs chapter of their online WebSTAR 4 Manual, including a link to their Developer Site which itself has a 'Developer Resources' page that contains links to other sources of information. See especially the cited How to Write CGI Applications in AppleScript link to Jon Wiederspan's old "Extending WebSTAR" guide (that site may be down occasionally, as the link didn't work when I checked it tonight; you could also try this Extending WebSTAR mirror site).

Good luck,

--Paul
     
Fresh-Faced Recruit
Join Date: Dec 1999
Location: Lincoln, MA USA
Status: Offline
Reply With Quote
May 7, 2000, 08:26 AM
 
Ok. Well that helped alot. Now that it is staying open, it collectes the data fine. My new problem is i get the following error.
-------
Error -51, File reference number error.
----------
any ideas on what that means???
Thanks

-ben
     
Dedicated MacNNer
Join Date: Nov 1999
Location: Georgetown, Demerara, Guyana
Status: Offline
Reply With Quote
May 8, 2000, 05:24 PM
 
Hi Ben,

The 'Error -51' may be related to a minor typo in the placement of the parentheses within the statement:- 'if get eof (fileNumber < 1) then ...'.

Instead, try rephrasing that statement like this:- 'if (get eof filenumber) < 1 then...'.

Regards,

--Paul
     
Fresh-Faced Recruit
Join Date: Dec 1999
Location: Lincoln, MA USA
Status: Offline
Reply With Quote
May 8, 2000, 08:47 PM
 
That was it!! Thanks!!!!

-Ben
     
Fresh-Faced Recruit
Join Date: Dec 1999
Location: Lincoln, MA USA
Status: Offline
Reply With Quote
May 8, 2000, 09:00 PM
 
Originally posted by travisres:
That was it!! Thanks!!!!

-Ben
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 11:03 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2