Hi,
I have a script where I want to submit applescript form data (s) via curl to db via php page.
My problem is converting “&” and space characters (any other common characters) so mysql will accept it.
Right now, If I subtitute %20 (space character) and %26 (ampersand) (manually by hand) it will insert the row record into my database.
Can someone tell me how to convert myURL
set checkit to (do shell script "curl " & quoted form of myURL)
Looks like this when I manually substitute in space and ampersand characters:
(It will insert into my database)
“http://www.domain.com/add_record.php?bname=Tom&zname=Larson&eventtitle=Meeting%20Room&vurl=http://bucket.s3.amazonaws.com/_videos/121709/1217096pm.wmv&eventcomment=Tim%20%26%20Neenah&eventfeatured=0”
My current script tries this with just the insert query string( I concatenate the root domain to the query string":
set escapedURL to do shell script “php -r 'echo urlencode("” & myURL & “");'”
This gives me all urlencoded =,space,? and ampersand equivalents BUT does not enter a record into mysql.
SOooooo. My question is:
Does someone have an idea how I can scrub my query string variable myURL character by character to replace any space and ampersand and possibly (!and*) characters with %20 and %26 and ((!and*)) equivalents?
When you encode the entire url, you are encoding characters like “/”, “:”, “&” etc. As such your url isn’t properly formed any longer. For example “http://” becomes “http%3A%2F%2F”. Therefore a solution would be to just encode the parts of the url that need to be encoded. Something like this…
-- the url parts
set domainURL to "http://www.domain.com/add_record.php?"
set bname to "Tom"
set zname to "Larson"
set eventTitle to "Meeting Room"
set vurl to "http://bucket.s3.amazonaws.com/_videos/121709/1217096pm.wm"
-- escape only the php parameters
set bnameEscaped to do shell script "php -r 'echo urlencode(\"" & bname & "\");'"
set znameEscaped to do shell script "php -r 'echo urlencode(\"" & zname & "\");'"
set eventTitleEscaped to do shell script "php -r 'echo urlencode(\"" & eventTitle & "\");'"
set vurlEscaped to do shell script "php -r 'echo urlencode(\"" & vurl & "\");'"
-- put the url together
set escapedURL to domainURL & "bname=" & bnameEscaped & "&zname=" & znameEscaped & "&eventtitle=" & eventTitleEscaped & "&vurl=" & vurlEscaped
-- send it to php website
set checkit to do shell script "curl " & quoted form of escapedURL
regulus6633,
That worked perfect. Thank you. I have been struggling with that for a week.
Tak and sincerely,
Jeff