Mysql Database Comparing Data Together

I am getting nil for rs and not sure what to do I understand that I am not using rs right now so that is why it is getting nil but not sure how to use it properly, can someone help thanks.

after the select statement you should do like this
if rs <> Nil Then
if not rs.EOF Then
if username.text …
else
end if
end if
end if

Welcome to Xojo. Please post your code and not a screenshot. You need to add an NOE check and then you need to find out why your SQL doesn’t work.

Untested code:

if not db.connect then
  Messagebox "Error here"
  return
end if

dim rs as RecordSet = db.SQLSelect("some sql")
if rs = nil then
  Messagebox "Error here"
  return
end if

Username.text = rs.field("username")

Well that is the thing I know it is nil because it keeps coming up and I can handle getting the error just need to figure out to use rs.field(“username”) because it says it is nil and I tried the examples it didn’t fix it, thanks though

I figured it out I had password there too but wasn’t using it when calling it in SelectSQL so that fixed it, thanks

I got everything working but now when I add the check for the password it says incorrect and I know it is right but if I remove the + symbols it gives me a nil error what setup am I missing it looked right to me, thanks

rs = db.SelectSQL("SELECT * FROM login_server WHERE username='" + Username.text + "'+ password= +'" + Password.text + "'")

I figured it out I had to change my format and without the + symbols altogether, thanks

You may want to use parameters in your query instead of concatenating strings. This has two benefits. First, it makes reading (and debugging) your query easier. Second, you are less vulnerable to a SQL injection attack.

Instead of

rs = db.SelectSQL("SELECT * FROM login_server WHERE username='" + Username.text + "'+ password= +'" + Password.text + "'")

Use

rs = db.SelectSQL("SELECT * FROM login_server WHERE username = ? AND password = ?", Username.text, Password.text)

(Side note: you probably want to use the SQL keyword AND in your WHERE clause like in my example and not the + operator.)

[Edit to fix a syntax error in the post]

Obligatory mention of xkcd: xkcd: Exploits of a Mom

2 Likes