update Username
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
update Username
hi, in my stack the user at the opening, writes a Username, but he can change it afterwards, i was thinking, how can i update that on sql? then i had an adea to make an Auto Increment record that is like the id of the user, but i don't know how can i take that data (the ID) when its created, and then maybe from there i can put it on a field so then every time the username changes his username the record can be updated (because every Username has also a High Score record).
so basically the question is, how can i know what's the user ID after he changed his Username?
thanks!
so basically the question is, how can i know what's the user ID after he changed his Username?
thanks!
Samuele.
Re: update Username
When the user enters his name (before changing it), how do you check if that user is valid?
I guess you do some SQL here, so you should fetch the ID of the user, too.
Then store it in a (hidden) field or custom property, then use it late to update the username.
Pseudo SQL code:
I guess you do some SQL here, so you should fetch the ID of the user, too.
Then store it in a (hidden) field or custom property, then use it late to update the username.
Pseudo SQL code:
Code: Select all
update 'usernames' set 'username' = (the new username) where ID = (the value from field or custom property)
Re: update Username
yes i do, i check if it's already in the database (in use)
how can i get from here the id?
Code: Select all
put "SELECT EXISTS(SELECT * from " & tTableName & " WHERE UserName = " & ' & _guserName & ' & ")" into tSQL
put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tAnswer
put tAnswer into field "gg"
if tAnswer = "1"
then
answer "Username already exists"
#if the environment is "mobile" then
set the text of widget "EnterUsername" to empty
exit to top
else
Samuele.
Re: update Username
i've put this code in a button "OK" that appears when the user wants to change the username, but it doesn't work, any ideas? thanks!
in the field ID there is the id, i checked, so i don't know what's the problem because it doesn't even give an error, but it doesn't update the username
thanks!
Code: Select all
put "Persons" into tTableName
put "UserName, HighScore" into tFields
put field "UserName" of card "HomeCard" into tUsername
put field "ID" of card "HomeCard" into tID
put "UPDATE " & tTableName & " SET Username= " & ' & tUsername & ' & " WHERE PersonId= " & tUsername into tSQL
revExecuteSQL gConnectionID, tSQL
thanks!
Samuele.
Re: update Username
put "UPDATE " & tTableName & " SET Username= " & ' & tUsername & ' & " WHERE PersonId= " & tUsername into tSQL
Sure?
Sure?
Re: update Username
Hi,
Shouldn't the single quotes be inside the double quotes as well.
But as Klaus points out that maybe your username column in the database is not called PersonID.
Shouldn't the single quotes be inside the double quotes as well.
Code: Select all
put "Persons" into tTableName
put "UserName, HighScore" into tFields
put field "UserName" of card "HomeCard" into tUsername
put field "ID" of card "HomeCard" into tID
put "UPDATE " & tTableName & " SET Username= '" & tUsername & "' WHERE PersonId= '" & tUsername & "'" into tSQL
revExecuteSQL gConnectionID, tSQL
Regards
Andy
DB Integration Limited
Andy
DB Integration Limited
Re: update Username
If this is a question, then the answer is YES!Shouldn't the single quotes be inside the double quotes as well.
I always use these functions when it come to work with databases, of course helpful in other situations, too!
They will QUOTE or SINGEL QUOTE a passed string:
Code: Select all
## QUotes:
function q tString
return QUOTE & tString & QUOTE
end q
## Single quotes
function q2 tString
return "'" & tString & "'"
end q2
Re: update Username
yes , right i changed it
and for the single quotes they are inside the double quotes as well.
now it works, thanks!
Code: Select all
put field "TypeUser" into tUsername
put field "ID" of card "HomeCard" into tID
put "UPDATE " & tTableName & " SET Username= " & ' & tUsername & ' & " WHERE PersonId= " & tID into tSQL
revExecuteSQL gConnectionID, tSQL
now it works, thanks!
Samuele.
Re: update Username
Not they aren't!
Code: Select all
" & ' & tUsername & ' & "...
# This is OUTSIDE the quotes
Code: Select all
...
## Hint: do not use SPACES, use the double &&
put "UPDATE" && q2(tTableName) && "SET Username= " & q2(tUsername) && "WHERE PersonId=" & q2(tID) into tSQL
...
Re: update Username
strange, because it works... so i don't want to change itKlaus wrote: ↑Thu Nov 25, 2021 12:06 pmNot they aren't!With my functions this is a snap and not prone to errors!Code: Select all
" & ' & tUsername & ' & "... # This is OUTSIDE the quotes
Code: Select all
... ## Hint: do not use SPACES, use the double && put "UPDATE" && q2(tTableName) && "SET Username= " & q2(tUsername) && "WHERE PersonId=" & q2(tID) into tSQL ...
Samuele.