Android Question Login Form using MySql in jRDC2 Help!

Hi! I'm an absolute newbie here, I need help in validating my database using MySQL.

here's my query
sql.validate=SELECT * FROM `tbl_userinfo` WHERE `Username` = '" & uName.Text & "' AND `Password`='" & pWord.Text & "'

In here, I have two edit texts, uName and pWord.

It works just fine when I assign custom values to the username and passwords (which exists in MySql table I made). I.E,
sql.validate=SELECT * FROM `tbl_userinfo` WHERE `Username` = "John" AND `Password`="123"

However it doesn't seem to work when I assign edittext variables.

here's my sub

Sub Button2_Click
Dim LoginStatus As Int
LoginStatus = 0
Dim req As DBRequestManager = CreateRequest
Dim cmd As DBCommand = CreateCommand("validate", Null)
Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
If j.Success Then
req.HandleJobAsync(j, "req")
Wait For (req) req_Result(res As DBResult)
'work with result
req.PrintTable(res)
If res.Rows.size > 0 Then
LoginStatus = 1

MsgboxAsync("Valid user ", "Login successful")
StartActivity("Home")
Else
LoginStatus=0
MsgboxAsync("Invalid user ","Login Unsuccessful")
End If
Else
Log("ERROR: " & j.ErrorMessage)
End If
j.Release

Note: I've already established connection using jRDC2
I also used a b4a member named anser's code as reference
 
B4X:
Sub Button2_Click
Dim LoginStatus As Int
LoginStatus = 0
Dim req As DBRequestManager = CreateRequest
Dim cmd As DBCommand = CreateCommand("validate", Null)
Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)
If j.Success Then
req.HandleJobAsync(j, "req")
Wait For (req) req_Result(res As DBResult)
'work with result
req.PrintTable(res)
If res.Rows.size > 0 Then
LoginStatus = 1

MsgboxAsync("Valid user ", "Login successful")
StartActivity("Home")
Else
LoginStatus=0
MsgboxAsync("Invalid user ","Login Unsuccessful")
End If
Else
Log("ERROR: " & j.ErrorMessage)
End If
j.Release
End Sub
 
Upvote 0

josejad

Expert
Licensed User
Longtime User
Take a look again to the jRDC2 Tutorial

You have to write your sql sentences passing parameters with ?, not with & uName.Text

B4X:
sql.validate=SELECT * FROM `tbl_userinfo` WHERE `Username` = ? AND `Password`=?

You are not passing any parameter to jRDC2, you're passing Null
B4X:
Dim cmd As DBCommand = CreateCommand("validate", Array(uName.Text,  pWord.Text))
   Wait For (req.ExecuteQuery(cmd, 0, Null)) JobDone(j As HttpJob)

Maybe this sample helps you:
 
Upvote 0
OMY!!! THANK YOU!!! YOU'RE A LIFESAVER (sorry for the all caps) I was stuck for about 3days!!!! I dunno how I could repay you but, I hope something good comes your way. Kudos!

I wish I could learn faster and start helping out in the forum...
 
Upvote 0
Top