Android Question Httputils2 problems during update.

Dman

Active Member
Licensed User
Longtime User
I am having a problem updating a record on a mysql database.

This works fine as long as there are no special characters.

B4X:
Sub btnUpdate_Click
data="op=updatemember" & _
        "&id=" & memberid & _
        "&firstname=" & editfirstname.Text & _
        "&lastname=" & editlastname.Text & _
        "&company=" & editCompany.text
Log (data)
getdata("updatemember",data)
End Sub

Sub getdata(jobname As String,jobdata As String)
job1.Initialize(jobname, Me)
job1.Download("http://www.whatever.com/getdata.php?" &jobdata)
End Sub

It quit updating when I urlencode it like this
B4X:
Sub btnUpdate_Click
data="op=updatemember" & _
        "&id=" & memberid & _
        "&firstname=" & editfirstname.Text & _
        "&lastname=" & editlastname.Text & _
        "&company=" & editCompany.text
Log (data)
Dim su As StringUtils
data = su.EncodeUrl(data, "UTF8")
getdata("updatemember",data)
End Sub

Sub getdata(jobname As String,jobdata As String)
job1.Initialize(jobname, Me)
job1.Download("http://www.whatever.com/getdata.php?" &jobdata)
End Sub

I thought that download2 would work better maybe but it doesn't update either.

B4X:
Sub btnUpdate_Click
updatedata("updatemember","op=updatemember")
End Sub

Sub updatedata(jobname As String,jobdata As String)
job2.Initialize(jobname, Me)
job2.Download2("http://www.whatever.com/getdata.php?" &jobdata,Array As String("id", memberid,"firstname",editfirstname.text,"lastname",editlastname.Text,"company",editCompany.text))
End Sub

Any ideas on what I am overlooking?
 

Dman

Active Member
Licensed User
Longtime User
Does this not url encode the parameters?

B4X:
data="op=updatemember" & _
        "&id=" & memberid & _
        "&firstname=" & editfirstname.Text & _
        "&lastname=" & editlastname.Text & _
        "&company=" & editCompany.text
Log (data)
Dim su As StringUtils
data = su.EncodeUrl(data, "UTF8")
getdata("updatemember",data)
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
since you encode the entire parameterblock you ruined the parameter definers

so it changed it to op=updatemember&id ...

you need to od it like this


B4X:
Dim su AsStringUtils
data="op=updatemember" & _
        "&id=" & su.EncodeUrl(memberid, "UTF8") & _
        "&firstname=" & su.EncodeUrl(editfirstname.Text, "UTF8") & _
        "&lastname=" & su.EncodeUrl(editlastname.Text, "UTF8") & _
        "&company=" & su.EncodeUrl(editCompany.text, "UTF8")
Log (data)
 
Upvote 0

Dman

Active Member
Licensed User
Longtime User
Well there you go. That works like a charm when having spaces. I guess the 7 or 8 hours I invested in that yesterday was just wasted. :) Thanks!

Though when using a ' it inserts it into the database as \'

Does that seem right?
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
yes, that's the escaping char for mysql, when you read it out it will just show ' tho.
 
Upvote 0
Top