inserting, deleting and updating DB on push of one button
Posted: Fri Jan 09, 2015 7:06 am
I have a mobile app that is been made, but my headache has been based on the fact that i want the user to enter a code, if the code is in database, the point assigned with the code is added to users point, code is deleted from database, user point on both database and app are updated.
this has been my headache for day now. please help needed.
attached are the picture of app interface and code on it. the code is on the stack level. here is the code
on updatePoint
-- construct the SQL (this selects all the data from the specified table)
put "share" into tTableName -- set this to the name of a table in your database
put "SELECT Points FROM "&tTableName&" WHERE Username= '" & gUsername & "'" into tSQL
put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData -- query the database
if gConnectionID is not a number then -- check the result and display the data or an error message
answer error "There was a problem querying the database:" & cr & tData
else
put tData into gPoints
end if
end updatePoint
on getPoint
Put field "forCode" into tCodes
put "codes" into tTableCodes
put "SELECT Points FROM "&tTableCodes&" WHERE Codes= '" & tCodes & "'" into tSQL
put revDataFromQuery(tab, cr, gConnectionID, tSQL) into tData
Add tData to gPoints
put gPoint into tPoint
end getPoint
on upData
put field "forCode" into tCodes
put "codes" into tTableCodes
put gPoints
put "share" into tTableName
put "UPDATE "&tTableName&" SET Points= '"&tPoint&"' WHERE Username= '" & gUsername & "'" into tSQL
put "UPDATE "&tTableCodes&" SET Points= '0' WHERE Codes='" & tCodes & "'" into uSQL
put revDataFromQuery(tab, cr, gConnectionID, tSQL, uSQL) into tData
end upData
on the blue button i have created two handler which are on the stack level
on mouseDown
getPoint
end mouseDown
on mouseUp
upData
end mouseUp