MYSQL ID Auto Filling In The Information

I think your onto something though because I am not getting id’s initial value instead it is just adding the default one into the textfields instead of comparing the id to fill in the username and the rest of the information but not sure.

What is your code that sets id to an initial value before the SelectSQL runs?

That’s just it I do not have any code that sets the id to an initial value I am just looking for the id=? and it fills out all the information for me. I setup the database myself with the username and id 0 for codeman and id 1 for jsmith. but when I go to load it does not fill in jsmith’s information. I am really new to this so I am not to sure how to compare id 1 to jsmith and load the textfields depending on the id

If you don’t have any code to initialise id, then its value will default to zero thus leading to the behaviour you observe.

You talked about “logging in with a different username” so is this username available to your program after login? If so presumably you should be looking for that in the database rather than id.

No and when I use username nothing comes up so I stick with using id when I login with another user it still does codeman’s information and not the other one

  1. Presumably by “login” you mean that you have a window in your app with a username field and a password field. Is this the case?

  2. I further assume that you have a button labelled “Login” that you click, the idea being that after filling in the username/password, you click this button and the button’s “Pressed” event handler then runs the code you posted in your first post. Is this the case?

  3. If (1) and (2) are true, then your SelectSQL should look something like:

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

(the ?1 and ?2 are correct for SQLite, may be different for mysql).

  1. If either (1) or (2) is not true then we need to know what this “login” you refer to is, what are you logging into and what causes your code (from your first post), to run, and what information is available to that code.

Yes that is correct I have one with username and password field, and a button for Login. The sql you posted does the same thing as the other one it doesn’t show anything at all when using the username and password but it does for id so this is really strange. There has to be a way to tell it if the id is 0 to put my information in if it is 1 but jsmith’s information in.

Have you stepped though with the debugger to see that it actually executes your SelectSQL() ?


I removed the if statement to make sure and it is for sure but it is giving me nil for rs

Then either the table login_server doesn’t exist in your database or there is no column named id.


Yeah both are there

:thinking:

You sure you’re connected to the right db, then?

yeah I tested the connection it connected just fine this is mind blowing

Lets see the code for setting up the connection and connecting. NB I only do SQLite so someone else will have to comment on that bit.

But doan forget - your SelectSQL will have to use username and password even if the connect is correct.

Var db As New MySQLCommunityServer
db.Host = "gamingtsw.com"
db.Port = 3306
db.DatabaseName = "tsw_server"
db.UserName = "<Redacted by Moderator>"
db.Password = "<Redacted by Moderator>"

Var rs As RowSet

rs = db.SelectSQL("SELECT * FROM login_server WHERE id=?", id.text.ToInteger)
id.AddText(rs.Column("id").StringValue)
FirstName.AddText(rs.Column("first_name").StringValue)
LastName.AddText(rs.Column("last_name").StringValue)
Username.AddText(rs.Column("username").StringValue)
Password.AddText(rs.Column("password").StringValue)
Email.AddText(rs.Column("email").StringValue)
Gamertag.AddText(rs.Column("gamertag").StringValue)
Level.AddText(rs.Column("level").StringValue)
UserNotes.AddText(rs.Column("user_notes").StringValue)
AdminNotes.AddText(rs.Column("admin_notes").StringValue)

But this doesn’t connect to the database ???

Use 28@Sonder203 for the password and it will I changed it

Where is the db.Connect() statement ?

I removed it to test something but I put it back again.

what kind of object is id?
TextField1 or maybe a TextArea1?

use this and verify your filter is correct (and not have a line break)

Var searchtx As String = id.Text
System.DebugLog searchtx
Var searchid As Integer = searchtx.ToInteger
System.DebugLog searchid.ToString
Break

continue
if there are no result with the corrent filter
remove the id= filter, you should get the whole table.
and see what you get in the debugger.

i like to test it but the login was removed.