how to connect text fields to sqlite3 database collumns

local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") local sqlite3 = require ("sqlite3") local path = system.pathForFile("mobiledata.db", system.DocumentsDirectory) db = sqlite3.open(path) --Handle the applicationExit event to close the db local function onSystemEvent( event ) if( event.type == "applicationExit" ) then db:close() end end db:exec[[INSERT INTO users VALUES (NULL,firstnamebox,lastnamebox,usernamebox1,passwordbox1,passwordbox1, emailbox,dobbox,gender)]] ---------------------------------------------------------------------- -- create() Runtime:addEventListener("system",onSystemEvent) function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen local firstname = display.newText("FIRST NAME:",50,50,native.systemFont,14) firstname:setFillColor(1,1,1) sceneGroup:insert(firstname) firstnamebox = native.newTextField(240,50,170,20) firstnamebox.size = 14 firstnamebox.inputType = "text" local lastname = display.newText("LAST NAME:",50,85,native.systemFont,14) lastname:setFillColor(1,1,1) sceneGroup:insert(lastname) lastnamebox = native.newTextField(240,85,170,20) lastnamebox.sie= 14 lastnamebox.inputType = "text" local username1 = display.newText("USERNAME:",50,120, native.systemFont,14) username1:setFillColor(1,1,1) sceneGroup:insert(username1) usernamebox1 = native.newTextField(240,120,170,20) usernamebox1.size = 14 usernamebox1.inputType = "text" local password1 = display.newText("PASSWORD:",50,155,native.systemFont,14) password1:setFillColor(1,1,1) sceneGroup:insert(password1) passwordbox1 = native.newTextField(240,155,170,20) passwordbox1.size = 14 passwordbox1.inputType = "text" local repassword = display.newText("RETYPE PASSWORD:",80,190,native.systemFont,14) repassword:setFillColor(1,1,1) sceneGroup:insert(repassword) repasswordbox = native.newTextField(240,190,170,20) repasswordbox.size = 14 repasswordbox.inputType = "text" local email = display.newText("E-MAIL:",30,225,native.systemFont,14) email:setFillColor(1,1,1) sceneGroup:insert(email) emailbox = native.newTextField(240,225,170,20) emailbox.size = 14 emailbox.inputType = "text" local dob = display.newText("DATE OF BIRTH:",60,260,native.systemFont,14) dob:setFillColor(1,1,1) sceneGroup:insert(dob) dobbox = native.newTextField(240,260,170,20) dobbox.size = 14 dobbox.inputType = "date" local gender = display.newText("GENDER:",40,310,native.systemFont,14) gender:setFillColor(1,1,1) sceneGroup:insert(gender) local male = display.newText("MALE:",120,310,native.systemFont,14) male:setFillColor(1,1,1) sceneGroup:insert(male) local female = display.newText("FEMALE:",230,310,native.systemFont,14) female:setFillColor(1,1,1) sceneGroup:insert(female) local function onSwitchPress(event) local switch = event.target print("switch with ID'"..switch.id.."'is on: " ..tostring(switch.isOn)) end local male = widget.newSwitch( { left = 150, top = 295, style = "checkbox", id = "Checkbox", onPress = onSwitchPress } ) sceneGroup:insert(male) local female = widget.newSwitch( { left = 270, top = 295, style = "checkbox", id = "Checkbox", onPress = onSwitchPress } ) sceneGroup:insert(female) local nextpage = widget.newButton( { left = -20, top = 450, id = "nextpage", label = "NEXT", onEvent = handleButtonEvent } ) sceneGroup:insert(nextpage) function nextpage:touch(event) if (event.phase == "ended") then composer.removeScene("regform1",true) composer.gotoScene("regform2",{effect = "fade",time = 200}) end return true; end local cancel = widget.newButton( { left = 150, top = 450, id = "cancel", label = "CANCEL", onRelease = saveData, onEvent = handleButtonEvent } ) sceneGroup:insert(cancel) function cancel:touch(event) if (event.phase == "ended") then composer.removeScene("regform1",true) composer.gotoScene("login",{effect = "fade",time = 200}) end return true; end end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) firstnamebox:removeSelf() firstnamebox = nil lastnamebox:removeSelf() lastnamebox = nil usernamebox1:removeSelf() usernamebox1 = nil passwordbox1:removeSelf() passwordbox1 = nil repasswordbox:removeSelf() repasswordbox = nil emailbox:removeSelf() emailbox = nil dobbox:removeSelf() dobbox = nil elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene

[lua]

– follow same format for remaining fields, omit quote marks for integer fields.

local q = [[insert into users values (NULL, “]]…firstnamebox.text…[[”,"]]…lastnamebox.text…[[" );]]

db:exec(q)

[/lua]

local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") local sqlite3 = require ("sqlite3") local path = system.pathForFile("mobiledata.db", system.DocumentsDirectory) db = sqlite3.open(path) --Handle the applicationExit event to close the db local function onSystemEvent( event ) if( event.type == "applicationExit" ) then db:close() end end ---------------------------------------------------------------------- -- create() Runtime:addEventListener("system",onSystemEvent) function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen local firstname = display.newText("FIRST NAME:",50,50,native.systemFont,14) firstname:setFillColor(1,1,1) sceneGroup:insert(firstname) firstnamebox = native.newTextField(240,50,170,20) firstnamebox.size = 14 firstnamebox.inputType = "text" local lastname = display.newText("LAST NAME:",50,85,native.systemFont,14) lastname:setFillColor(1,1,1) sceneGroup:insert(lastname) lastnamebox = native.newTextField(240,85,170,20) lastnamebox.sie= 14 lastnamebox.inputType = "text" local username1 = display.newText("USERNAME:",50,120, native.systemFont,14) username1:setFillColor(1,1,1) sceneGroup:insert(username1) usernamebox1 = native.newTextField(240,120,170,20) usernamebox1.size = 14 usernamebox1.inputType = "text" local password1 = display.newText("PASSWORD:",50,155,native.systemFont,14) password1:setFillColor(1,1,1) sceneGroup:insert(password1) passwordbox1 = native.newTextField(240,155,170,20) passwordbox1.size = 14 passwordbox1.inputType = "text" local repassword = display.newText("RETYPE PASSWORD:",80,190,native.systemFont,14) repassword:setFillColor(1,1,1) sceneGroup:insert(repassword) repasswordbox = native.newTextField(240,190,170,20) repasswordbox.size = 14 repasswordbox.inputType = "text" local email = display.newText("E-MAIL:",30,225,native.systemFont,14) email:setFillColor(1,1,1) sceneGroup:insert(email) emailbox = native.newTextField(240,225,170,20) emailbox.size = 14 emailbox.inputType = "text" local dob = display.newText("DATE OF BIRTH:",60,260,native.systemFont,14) dob:setFillColor(1,1,1) sceneGroup:insert(dob) dobbox = native.newTextField(240,260,170,20) dobbox.size = 14 dobbox.inputType = "date" local gender = display.newText("GENDER:",40,310,native.systemFont,14) gender:setFillColor(1,1,1) sceneGroup:insert(gender) local male = display.newText("MALE:",120,310,native.systemFont,14) male:setFillColor(1,1,1) sceneGroup:insert(male) local female = display.newText("FEMALE:",230,310,native.systemFont,14) female:setFillColor(1,1,1) sceneGroup:insert(female) local function onSwitchPress(event) local switch = event.target print("switch with ID'"..switch.id.."'is on: " ..tostring(switch.isOn)) end local male = widget.newSwitch( { left = 150, top = 295, style = "checkbox", id = "Checkbox", onPress = onSwitchPress } ) sceneGroup:insert(male) local female = widget.newSwitch( { left = 270, top = 295, style = "checkbox", id = "Checkbox", onPress = onSwitchPress } ) sceneGroup:insert(female) local nextpage = widget.newButton( { left = -20, top = 450, id = "nextpage", label = "NEXT", onEvent = handleButtonEvent } ) sceneGroup:insert(nextpage) function nextpage:touch(event) if (event.phase == "ended") then local record ={} local q = [[INSERT INTO users VALUES (NULL, "]]..firstnamebox.text..[[","]] ..lastnamebox.text..[[","]]..usernamebox1.text..[[","]]..passwordbox1.text.. [[","]]..emailbox.text..[[","]]..dobbox.text..[[","]] ..gender.text..[[");]] db:exec(q) composer.removeScene("regform1",true) composer.gotoScene("regform2",{effect = "fade",time = 200}) end return true; end local cancel = widget.newButton( { left = 150, top = 450, id = "cancel", label = "CANCEL", onRelease = submitform, onEvent = handleButtonEvent } ) sceneGroup:insert(cancel) function cancel:touch(event) if (event.phase == "ended") then composer.removeScene("regform1",true) composer.gotoScene("login",{effect = "fade",time = 200}) end return true; end local function submitform(event) local record = {} record.first\_name = firstnamebox.text record.last\_name = lastnamebox.text record.username = usernamebox1.text record.password = passwordbox1.text record.email = emailbox.text record.dob = dobbox.date record.gender = gender.text db.create(record) end end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) firstnamebox:removeSelf() firstnamebox = nil lastnamebox:removeSelf() lastnamebox = nil usernamebox1:removeSelf() usernamebox1 = nil passwordbox1:removeSelf() passwordbox1 = nil repasswordbox:removeSelf() repasswordbox = nil emailbox:removeSelf() emailbox = nil dobbox:removeSelf() dobbox = nil elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene

it is now working this the code i use

[lua]

– follow same format for remaining fields, omit quote marks for integer fields.

local q = [[insert into users values (NULL, “]]…firstnamebox.text…[[”,"]]…lastnamebox.text…[[" );]]

db:exec(q)

[/lua]

local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") local sqlite3 = require ("sqlite3") local path = system.pathForFile("mobiledata.db", system.DocumentsDirectory) db = sqlite3.open(path) --Handle the applicationExit event to close the db local function onSystemEvent( event ) if( event.type == "applicationExit" ) then db:close() end end ---------------------------------------------------------------------- -- create() Runtime:addEventListener("system",onSystemEvent) function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen local firstname = display.newText("FIRST NAME:",50,50,native.systemFont,14) firstname:setFillColor(1,1,1) sceneGroup:insert(firstname) firstnamebox = native.newTextField(240,50,170,20) firstnamebox.size = 14 firstnamebox.inputType = "text" local lastname = display.newText("LAST NAME:",50,85,native.systemFont,14) lastname:setFillColor(1,1,1) sceneGroup:insert(lastname) lastnamebox = native.newTextField(240,85,170,20) lastnamebox.sie= 14 lastnamebox.inputType = "text" local username1 = display.newText("USERNAME:",50,120, native.systemFont,14) username1:setFillColor(1,1,1) sceneGroup:insert(username1) usernamebox1 = native.newTextField(240,120,170,20) usernamebox1.size = 14 usernamebox1.inputType = "text" local password1 = display.newText("PASSWORD:",50,155,native.systemFont,14) password1:setFillColor(1,1,1) sceneGroup:insert(password1) passwordbox1 = native.newTextField(240,155,170,20) passwordbox1.size = 14 passwordbox1.inputType = "text" local repassword = display.newText("RETYPE PASSWORD:",80,190,native.systemFont,14) repassword:setFillColor(1,1,1) sceneGroup:insert(repassword) repasswordbox = native.newTextField(240,190,170,20) repasswordbox.size = 14 repasswordbox.inputType = "text" local email = display.newText("E-MAIL:",30,225,native.systemFont,14) email:setFillColor(1,1,1) sceneGroup:insert(email) emailbox = native.newTextField(240,225,170,20) emailbox.size = 14 emailbox.inputType = "text" local dob = display.newText("DATE OF BIRTH:",60,260,native.systemFont,14) dob:setFillColor(1,1,1) sceneGroup:insert(dob) dobbox = native.newTextField(240,260,170,20) dobbox.size = 14 dobbox.inputType = "date" local gender = display.newText("GENDER:",40,310,native.systemFont,14) gender:setFillColor(1,1,1) sceneGroup:insert(gender) local male = display.newText("MALE:",120,310,native.systemFont,14) male:setFillColor(1,1,1) sceneGroup:insert(male) local female = display.newText("FEMALE:",230,310,native.systemFont,14) female:setFillColor(1,1,1) sceneGroup:insert(female) local function onSwitchPress(event) local switch = event.target print("switch with ID'"..switch.id.."'is on: " ..tostring(switch.isOn)) end local male = widget.newSwitch( { left = 150, top = 295, style = "checkbox", id = "Checkbox", onPress = onSwitchPress } ) sceneGroup:insert(male) local female = widget.newSwitch( { left = 270, top = 295, style = "checkbox", id = "Checkbox", onPress = onSwitchPress } ) sceneGroup:insert(female) local nextpage = widget.newButton( { left = -20, top = 450, id = "nextpage", label = "NEXT", onEvent = handleButtonEvent } ) sceneGroup:insert(nextpage) function nextpage:touch(event) if (event.phase == "ended") then local record ={} local q = [[INSERT INTO users VALUES (NULL, "]]..firstnamebox.text..[[","]] ..lastnamebox.text..[[","]]..usernamebox1.text..[[","]]..passwordbox1.text.. [[","]]..emailbox.text..[[","]]..dobbox.text..[[","]] ..gender.text..[[");]] db:exec(q) composer.removeScene("regform1",true) composer.gotoScene("regform2",{effect = "fade",time = 200}) end return true; end local cancel = widget.newButton( { left = 150, top = 450, id = "cancel", label = "CANCEL", onRelease = submitform, onEvent = handleButtonEvent } ) sceneGroup:insert(cancel) function cancel:touch(event) if (event.phase == "ended") then composer.removeScene("regform1",true) composer.gotoScene("login",{effect = "fade",time = 200}) end return true; end local function submitform(event) local record = {} record.first\_name = firstnamebox.text record.last\_name = lastnamebox.text record.username = usernamebox1.text record.password = passwordbox1.text record.email = emailbox.text record.dob = dobbox.date record.gender = gender.text db.create(record) end end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) firstnamebox:removeSelf() firstnamebox = nil lastnamebox:removeSelf() lastnamebox = nil usernamebox1:removeSelf() usernamebox1 = nil passwordbox1:removeSelf() passwordbox1 = nil repasswordbox:removeSelf() repasswordbox = nil emailbox:removeSelf() emailbox = nil dobbox:removeSelf() dobbox = nil elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene

it is now working this the code i use