I have written an app which allows an user to register and login. The data will be automatically stored in the SQLite database.
What I would achieve is to allow the user to view/edit its own credentials / contact information. In other words, retrieving data for that specific user.
That’s exactly what I would like to achieve but I don’t know how.
I have created a separate webpage, which is considered to be the ‘my profile’ page and I have added a Textfield, even though I don’t know how to retrieve / bind the data from the database to reflect in the textfield.
You do the SELECT statement and put the returned value into the textfield.
(Pseudo code…)
Dim rs as RecordSet
Dim ps as SQLitePreparedStatement
rs = db.SQLSelect("SELECT firstname, lastname FROM users WHERE userid=?")
// These two lines of code defines what the '?' in the statement represents.
ps.BindType(0, SQLitePreparedStatement.SQLITE_INTEGER)
ps.Bind(0, userid)
'<--
rs = ps.SQLSelect()
//check for errors and all that...
fld_firstname.Text = rs.Field("firstname").StringValue
fld_lastname.Text = rs.Field("lastname").StringValue
Dim rs as RecordSet
Dim ps as SQLitePreparedStatement
ps = SQLitePreparedStatement(db.Prepare("SELECT firstname, lastname FROM users WHERE userid=?"))
// These two lines of code defines what the '?' in the statement represents.
ps.BindType(0, SQLitePreparedStatement.SQLITE_INTEGER)
ps.Bind(0, userid)
'<--
rs = ps.SQLSelect()
//check for errors and all that...
fld_firstname.Text = rs.Field("firstname").StringValue
fld_lastname.Text = rs.Field("lastname").StringValue
In this specific case I have made a separate webpage (within Xojo of course ;-)), which must view the first name from the database, when the user has logged in (for this time only the first name to keep it simple).
My database is called: ‘mydatabase.sqlite’ and the table is called: ‘Gebruikers’ (Dutch for users), the column in the database of first name is called: ‘FirstName’ and it knows a primary key called: ‘UserID’
When I go to the added webpage and add a method and re-write your code into the one below: (I have marked the modified fields bold and the last sentence deleted).
Dim rs as RecordSet
Dim ps as SQLitePreparedStatement
ps = SQLitePreparedStatement(db.Prepare(“SELECT FirstName FROM Gebruikers WHERE UserID=?”))
// These two lines of code defines what the ‘?’ in the statement represents.
ps.BindType(0, SQLitePreparedStatement.SQLITE_INTEGER)
ps.Bind(0, UserID)
'<–
I can imagine that this would be an odd question, but where can I find the database property ? I already looked into the ‘Properties’ area in the ‘CONTENTS’ bar and I found a property called ‘DB’ and a the type is ‘SQLiteDatabase’ I have tried to replace ‘db’ into the aforementioned names.
The UserID field is indeed an integer in the SQLite database. I guess the database has been successfully connected as I am able to ad da user to the database (when the web app runs, without the code above).
I have watched the videos again and the aforementioned issues are resolved. Thank you for your help !
However when I login the FirstName would not show up in the TextField1 area.
The purpose of the code below would be to retrieve the ‘FirstName’ from the user logged in and show it into TextField1.
This code has been added as a Method.
[i] Dim rs as RecordSet
Dim ps as SQLitePreparedStatement
ps = SQLitePreparedStatement(db.Prepare(“SELECT FirstName FROM Gebruikers WHERE UserID=?”))
// These two lines of code defines what the ‘?’ in the statement represents.
ps.BindType(0, SQLitePreparedStatement.SQLITE_INTEGER)
ps.Bind(0, UserID)
'<–