Page 1 of 1

What's wrong with this code?

Posted: Fri Jun 27, 2014 6:21 pm
by shawnblc
What's wrong with this code? I'm getting 'verified' nearly all the time.

Code: Select all

on mouseUp
    put fld "fldReceipt" into tReceipt
    put word 4 of line 1 of URL "http://domain.com/app.php?receipt="&tReceipt&"" into tConfirmation
    
    if tConfirmation = tReceipt then
        put "Verified" into fld "fldReceipt" else
        put "Not Verified" into fld "fldReceipt"
    end if
end mouseUp

Re: What's wrong with this code?

Posted: Fri Jun 27, 2014 6:30 pm
by Klaus
Hi shawn,

did you verify that the webpage is loading correctly?

Try this:

Code: Select all

on mouseUp
    put fld "fldReceipt" into tReceipt
    put word 4 of line 1 of URL ("http://domain.com/app.php?receipt=" & tReceipt) into tConfirmation
    
    if tConfirmation = tReceipt then
        put "Verified" into fld "fldReceipt" 
    ELSE
        put "Not Verified" into fld "fldReceipt"
    end if
end mouseUp
You can also ANSWER tReceipt and tConfirmation, will cause the "AHA" effect most of the time :D
And "debugging" the script might also help 8)


Best

Klaus

Re: What's wrong with this code?

Posted: Fri Jun 27, 2014 7:30 pm
by shawnblc
When I use the following, both match. Still everything is verified.

Code: Select all


answer tReceipt

Code: Select all

answer tConfirmation

Re: What's wrong with this code?

Posted: Fri Jun 27, 2014 8:37 pm
by dunbarx
Hi.

The code runs fine. What is in fld "tReceipt" at the getgo? I get "tReceipt" from the web page. In other words, what is being compared to what?

Craig

Re: What's wrong with this code?

Posted: Fri Jun 27, 2014 10:51 pm
by magice
I'm not sure if this will help, but I have had trouble in the past with concatenating a string within a URL before. It was probably a problem with the quotation marks, but I fixed it by concatenating the URL string into a variable instead and then using just the variable within the put URL command. This gave me an opportunity to check the url with an answer command before retrieving the data.

Re: What's wrong with this code?

Posted: Fri Jun 27, 2014 11:52 pm
by FourthWorld
When the engine sees this:

Code: Select all

put word 4 of line 1 of URL "http://domain.com/app.php?receipt="&tReceipt&"" into tConfirmation
...it thinks:
1. Get the URL
2. Get line 1 of the value returned from the server
3. Get word 4 of that line
4. Append tReceipt to that
5. Put all that into tConfirmation

To help the engine understand that you want tReceipt appended to the URL rather than the result of the URL, try using parentheses for making the order of evaluation more explicit, as in:

Code: Select all

put word 4 of line 1 of URL ("http://domain.com/app.php?receipt="&tReceipt&"") into tConfirmation