I am trying to create a textbox and get user input into it. The user’s input will be stored inside a sqlite database table. But when I try to display the user’s input, I see no output on the screen.
location is the variable user enters and on pressing enter, is Inserted into the table.
I feel like I’m missing some tiny logic. Please help !
Here is my piece of code:
NOTE: You can input in Textbox only in your OSX simulator, any device or use android simulator like Bluestacks. You can only see a grey box in Windows Corona SDK display.
require "sqlite3" local path = system.pathForFile("user.db", system.DocumentsDirectory) db = sqlite3.open( path ) local function onSystemEvent( event ) if( event.type == "applicationExit" ) then db:close() end end local tablesetup = [[CREATE TABLE IF NOT EXISTS place (id INTEGER PRIMARY KEY, location);]] print(tablesetup) db:exec( tablesetup ) local background = display.newRect(0,0,\_W,\_H) background:setFillColor(0,0,0) local locationTxtbox = native.newTextField(180,140,280,100) locationTxtbox.size = 34 locationTxtbox:addEventListener("textListener",locationTxtbox) local function textListener( event ) --user enters textbox if ( event.phase == "began" ) then -- user begins editing defaultField event.target.text = '' --user touches somewhere outside the textbox elseif ( event.phase == "ended" ) then -- do something with defaultField text local location = event.target.text --user types something elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) --user presses enter after typing, add to database table elseif ( event.phase == "submitted" ) then local location = event.target.text local tablefill =[[INSERT INTO place VALUES ("40",']]..location..[[');]] print( event.target.text ) db:exec(tablefill) end end --Displaying whatever user entered in the textbox and pressed enter. for row in db:nrows("SELECT \* FROM place") do local text = row.location local t = display.newText(text, 250, 120, native.systemFont, 40) end Runtime:addEventListener( "system", onSystemEvent )