Global variables have nil value, attempt to call global (a nil value)

I attempt to get data (in a global variable) from user through a textbox from the user in functions, and use these variables to insert into a sqlite table.

But, when I attempt to do so, I get an error like “attempt to concatenate global locationGlobal (a nil value)” in the INSERT INTO line, after I click the submit button.

NOTE : I input values in the textbox by using Bluestacks android simulator as inputting the text is not possible in windows Corona SDK. Here is my code :

local widget = require("widget") require "sqlite3" local path = system.pathForFile("testUser.db", system.DocumentsDirectory) db = sqlite3.open( path ) --local location,area,arrivalTime,departTime,eventAttended local function onSystemEvent( event ) if( event.type == "applicationExit" ) then db:close() end end --local tablesetup = [[CREATE TABLE IF NOT EXISTS visitPlace (id INTEGER PRIMARY KEY autoincrement, location, area, arrivalTime, departTime, eventAttended);]] local tablesetup = [[CREATE TABLE visitPlace (id INTEGER PRIMARY KEY autoincrement, location);]] print(tablesetup) db:exec( tablesetup ) \_W = display.viewableContentWidth \_H = display.viewableContentHeight local background = display.newRect(0,0,\_W,\_H) background:setFillColor(0,0,0) local function textListenerLocation( event ) if ( event.phase == "began" ) then -- user begins editing defaultField event.target.text = '' print(location) print( event.text ) elseif ( event.phase == "ended" ) then -- do something with defaultField text locationGlobal = tostring( event.target.text) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) elseif ( event.phase == "submitted" ) then locationGlobal =tostring( event.target.text) end end local function SubmitEvent( event ) --local label = display.newText( location, 180, 30, native.systemFontBold, 20 ) --label:setFillColor( 190/255, 190/255, 1 ) local insertionTable = [[INSERT INTO visitPlace VALUES(NULL,']]..locationGlobal..[[')]] db:exec(insertionTable) for row in db:nrows("SELECT \* FROM visitPlace") do local text = row.location local t = display.newText(text, 450, 120\*row.id, native.systemFont, 40) t:setFillColor(1,0,1) end local label1 = display.newText( "Submitted", 180, 30, native.systemFontBold, 20 ) label1:setFillColor( 190/255, 190/255, 1 ) end function background:tap( event ) native.setKeyboardFocus(nil) end local locationTxtbox = native.newTextField(180,140,280,100) locationTxtbox.size = 34 locationTxtbox:addEventListener("textListenerLocation",locationTxtbox) local submitButton = widget.newButton { label = "Submit", onEvent = SubmitEvent, shape = "roundedRect", width = 100, height = 30, cornerRadius = 2 } submitButton.x = display.contentCenterX + (display.contentCenterX/2) submitButton.Y = display.contentCenterY + (display.contentCenterY/2) background:addEventListener("tap",background) Runtime:addEventListener( "system", onSystemEvent ) --defaultField = native.newTextField( 150, 150, 180, 30 ) --defaultField:addEventListener( "userInput", textListener )

Looks like event.target.text is nil for some reason.

Rob

Is there any other method to get text entered by the user ?

You have two things going on.  First your event listener setup isn’t correct.  Try this:

locationTxtbox:addEventListener(“userInput”,textListenerLocation)

Next your button’s onEvent function is not handling the fact that it gets called twice, once when the button’s touch begins and another when it’s ended.

Rob

Edited to this. Same error persists.

Is the onEvent function rectified here ?

local widget = require("widget") require "sqlite3" local path = system.pathForFile("testUser.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 visitPlace (id INTEGER PRIMARY KEY autoincrement, location, area, arrivalTime, departTime, eventAttended);]] print(tablesetup) db:exec( tablesetup ) \_W = display.viewableContentWidth \_H = display.viewableContentHeight local bg = display.newImage ("Default-568h@2x.png"); bg.x = \_W/2;bg.y = \_H/2; bg:toBack(); local function textListenerLocation( event ) if ( event.phase == "began" ) then -- user begins editing defaultField event.target.text = '' print(location) print( event.text ) elseif ( event.phase == "ended" ) then -- do something with defaultField text locationGlobal = tostring( event.target.text) print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) end end local function SubmitEvent( event ) local insertionTable = [[INSERT INTO visitPlace VALUES(NULL,']]..locationGlobal..[[')]] db:exec(insertionTable) for row in db:nrows("SELECT \* FROM visitPlace") do local text = row.location local t = display.newText(text, 450, 120\*row.id, native.systemFont, 40) t:setFillColor(1,0,1) end local label1 = display.newText( "Submitted", 180, 30, native.systemFontBold, 20 ) label1:setFillColor( 190/255, 190/255, 1 ) end local label1 = display.newText( "Location", 180, 50, native.systemFontBold, 30 ) label1:setFillColor( 0, 0, 0 ) local locationTxtbox = native.newTextField(180,140,280,100) locationTxtbox.size = 34 locationTxtbox:addEventListener("userInput",textListenerLocation) local submitButton = widget.newButton { label = "Submit", onEvent = SubmitEvent, shape = "roundedRect", width = 200, height = 50, cornerRadius = 2 } submitButton.x = 180 submitButton.y = 1050 Runtime:addEventListener( "system", onSystemEvent )
local function SubmitEvent( event )     if "ended" == event.phase then         local insertionTable = [[INSERT INTO visitPlace VALUES(NULL,']]..locationGlobal..[[')]]         db:exec(insertionTable)         for row in db:nrows("SELECT \* FROM visitPlace") do             local text = row.location             local t = display.newText(text, 450, 120\*row.id, native.systemFont, 40)             t:setFillColor(1,0,1)         end         local label1 = display.newText( "Submitted", 180, 30, native.systemFontBold, 20 )         label1:setFillColor( 190/255, 190/255, 1 )     end end

Please post the text of the error message and the current code.

Rob

This is my complete code. I create multiple boxes and implement similar functions in each

local widget = require("widget") require "sqlite3" --Open data.db. If the file doesn't exist it will be created local path = system.pathForFile("testUser.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 local tablesetup = [[CREATE TABLE IF NOT EXISTS visitPlace (id INTEGER PRIMARY KEY autoincrement, location, area, arrivalTime, departTime, eventAttended);]] print(tablesetup) db:exec( tablesetup ) \_W = display.viewableContentWidth \_H = display.viewableContentHeight background = display.newImage ("Default-568h@2x.png"); background.x = \_W/2;background.y = \_H/2; background:toBack(); --Inserting Sample Values --local insertionTable = [[INSERT INTO visitPlace VALUES(NULL,'India Gate','Delhi','8:00am','10:30pm','Meeting' )]] -- db:exec(insertionTable) --local insertionTable = [[INSERT INTO visitPlace VALUES(NULL,'Lotus Temple','Delhi','2:00pm','5:00pm','Relaxing' )]] -- db:exec(insertionTable) local function textListenerArea( event ) if ( event.phase == "began" ) then -- user begins editing defaultField event.target.text = '' print(location) print( event.text ) elseif ( event.phase == "ended" ) then -- do something with defaultField text areaGlobal = tostring( event.target.text ) print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) end end local function textListenerEventAttended( event ) if ( event.phase == "began" ) then -- user begins editing defaultField event.target.text = '' print( event.text ) elseif ( event.phase == "ended" or event.phase == "submitted") then -- do something with defaultField text eventAttendedGlobal = tostring( event.target.text) print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) end end local function textListenerArrival( event ) if ( event.phase == "began" ) then -- user begins editing defaultField event.target.text = '' print(location) print( event.text ) elseif ( event.phase == "ended" ) then -- do something with defaultField text arrivalTimeGlobal = tostring( event.target.text) print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) end end local function textListenerDepart( event ) if ( event.phase == "began" ) then -- user begins editing defaultField event.target.text = '' print(location) print( event.text ) elseif ( event.phase == "ended" ) then -- do something with defaultField text departGlobal = tostring( event.target.text) print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) -- elseif ( event.phase == "submitted" ) then -- departGlobal = tostring( event.target.text) --departGlobal = "default" end end local function textListenerLocation( event ) if ( event.phase == "began" ) then -- user begins editing defaultField event.target.text = '' print(location) print( event.text ) elseif ( event.phase == "ended") then -- do something with defaultField text locationGlobal = tostring( event.target.text) print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) cationGlobal =tostring( event.target.text) end end local function SubmitEvent( event ) -- local label = display.newText( location, 180, 30, native.systemFontBold, 20 ) -- label:setFillColor( 190/255, 190/255, 1 ) if "ended" == event.phase then local insertionTable = [[INSERT INTO visitPlace VALUES(NULL,']]..locationGlobal..[[',']]..areaGlobal..[[',']]..arrivalTimeGlobal..[[',']]..departTimeGlobal..[[',']]..eventAttendedGlobal..[[' )]] db:exec(insertionTable) for row in db:nrows("SELECT \* FROM visitPlace") do local text = row.location local text2 = row.area local text3 = row.event local t = display.newText(text, 450, 120\*row.id, native.systemFont, 40) t:setFillColor(1,0,1) local t2 = display.newText(text2, 450, 120\*row.id, native.systemFont, 40) t2:setFillColor(1,0,1) local t3 = display.newText(text3, 450, 120\*row.id, native.systemFont, 40) t3:setFillColor(1,0,1) end local label1 = display.newText( "Submitted", 180, 30, native.systemFontBold, 20 ) label1:setFillColor( 190/255, 190/255, 1 ) end end function background:tap( event ) native.setKeyboardFocus(nil) -- body end local label1 = display.newText( "Location", 180, 50, native.systemFontBold, 30 ) label1:setFillColor( 0, 0, 0 ) local locationTxtbox = native.newTextField(180,140,280,100) locationTxtbox.size = 34 locationTxtbox:addEventListener("userInput",textListenerLocation) local label2 = display.newText( "Area", 180, 250, native.systemFontBold, 30 ) label2:setFillColor( 0, 0, 0 ) local areaTxtbox = native.newTextField(180,340,280,100) areaTxtbox.size = 34 areaTxtbox:addEventListener("userInput",textListenerArea) local label3 = display.newText( "Arrival Time" , 180, 450, native.systemFontBold, 30 ) label3:setFillColor( 0, 0, 0 ) local arrivalTimeTxtbox = native.newTextField(180,540,280,100) arrivalTimeTxtbox.size = 34 arrivalTimeTxtbox:addEventListener("userInput",textListenerArrival) local label4 = display.newText( "Departure Time", 180, 650, native.systemFontBold, 30 ) label4:setFillColor( 0, 0, 0 ) local destTimeTxtbox = native.newTextField(180,740,280,100) destTimeTxtbox.size = 34 destTimeTxtbox:addEventListener("userInput",textListenerDepart) local label5 = display.newText( "Event Attended", 180, 850, native.systemFontBold, 30 ) label5:setFillColor( 0, 0, 0 ) local eventTxtbox = native.newTextField(180,940,280,100) eventTxtbox.size = 34 eventTxtbox:addEventListener("userInput",textListenerEventAttended) local submitButton = widget.newButton { label = "Submit", onEvent = SubmitEvent, shape = "roundedRect", width = 200, height = 50, cornerRadius = 2 } submitButton.x = 180 submitButton.y = 1050 background:addEventListener("tap",background) Runtime:addEventListener( "system", onSystemEvent )

Error Message : 

Runtime Error

.\main.lua:155:attempt to concatenate global ‘eventAttendedGlobal’ (a nil value)

You’ve been saying “same error”.  But the error above is different:

.\main.lua:155:attempt to concatenate global ‘eventAttendedGlobal’ (a nil value)

attempt to concatenate global locationGlobal (a nil value)"

Are totally different errors.  In the case of the 2nd one, you didn’t point us to the line number but in this case they are the same line number.   In the 2nd message, you can clearly see the error is happening with a different variable.  In your first report, locationGlobal was the cause.  You’ve fixed it, because now eventAttendedGlobal is now causing the error.   In both cases, it’s a nil value, but when you tell us it’s the same error and I know the code I provided fixed it, it’s very hard to trouble shoot.  You need to learn to read the entire message.  Find the line number, the variable and the cause of the error.  All are right there for you.

Now that said I don’t see why you’re getting this error unless you don’t fill the field out.  You do however have this error:

Attempt to concatenate global ‘departTimeGlobal’ (a nil value)

But in that case your saving your text to “departGlobal” not “departTimeGlobal”.    I personally would not use the ended/submit phases to collect your data.  When you submit your form, just access the object’s .text attribute, perhaps something like this:

local function SubmitEvent( event ) -- local label = display.newText( location, 180, 30, native.systemFontBold, 20 ) -- label:setFillColor( 190/255, 190/255, 1 )     if "ended" == event.phase then         local insertionTable = [[INSERT INTO visitPlace VALUES(NULL,']]..locationTextbox.text..[[',']]..areaTextbox.text..[[',']]..arrivalTimeTextbox.text..[[',']]..departTimeTextbox.text..[[',']]..eventTextbox.text..[[' )]]           db:exec(insertionTable)           for row in db:nrows("SELECT \* FROM visitPlace") do             local text = row.location             local text2 = row.area             local text3 = row.event             local t = display.newText(text, 450, 120\*row.id, native.systemFont, 40)             t:setFillColor(1,0,1)             local t2 = display.newText(text2, 450, 120\*row.id, native.systemFont, 40)             t2:setFillColor(1,0,1)             local t3 = display.newText(text3, 450, 120\*row.id, native.systemFont, 40)             t3:setFillColor(1,0,1)         end         local label1 = display.newText( "Submitted", 180, 30, native.systemFontBold, 20 )         label1:setFillColor( 190/255, 190/255, 1 )     end end

but for this to work, you would need to move this function just above where you define the button since it references the fields directly and where the submit function is, those fields are not defined.  This also gets out out of using a bunch of global variables which are considered bad unless you’re experienced and you know what you’re doing.

Rob

Looks like event.target.text is nil for some reason.

Rob

Is there any other method to get text entered by the user ?

You have two things going on.  First your event listener setup isn’t correct.  Try this:

locationTxtbox:addEventListener(“userInput”,textListenerLocation)

Next your button’s onEvent function is not handling the fact that it gets called twice, once when the button’s touch begins and another when it’s ended.

Rob

Edited to this. Same error persists.

Is the onEvent function rectified here ?

local widget = require("widget") require "sqlite3" local path = system.pathForFile("testUser.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 visitPlace (id INTEGER PRIMARY KEY autoincrement, location, area, arrivalTime, departTime, eventAttended);]] print(tablesetup) db:exec( tablesetup ) \_W = display.viewableContentWidth \_H = display.viewableContentHeight local bg = display.newImage ("Default-568h@2x.png"); bg.x = \_W/2;bg.y = \_H/2; bg:toBack(); local function textListenerLocation( event ) if ( event.phase == "began" ) then -- user begins editing defaultField event.target.text = '' print(location) print( event.text ) elseif ( event.phase == "ended" ) then -- do something with defaultField text locationGlobal = tostring( event.target.text) print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) end end local function SubmitEvent( event ) local insertionTable = [[INSERT INTO visitPlace VALUES(NULL,']]..locationGlobal..[[')]] db:exec(insertionTable) for row in db:nrows("SELECT \* FROM visitPlace") do local text = row.location local t = display.newText(text, 450, 120\*row.id, native.systemFont, 40) t:setFillColor(1,0,1) end local label1 = display.newText( "Submitted", 180, 30, native.systemFontBold, 20 ) label1:setFillColor( 190/255, 190/255, 1 ) end local label1 = display.newText( "Location", 180, 50, native.systemFontBold, 30 ) label1:setFillColor( 0, 0, 0 ) local locationTxtbox = native.newTextField(180,140,280,100) locationTxtbox.size = 34 locationTxtbox:addEventListener("userInput",textListenerLocation) local submitButton = widget.newButton { label = "Submit", onEvent = SubmitEvent, shape = "roundedRect", width = 200, height = 50, cornerRadius = 2 } submitButton.x = 180 submitButton.y = 1050 Runtime:addEventListener( "system", onSystemEvent )
local function SubmitEvent( event )     if "ended" == event.phase then         local insertionTable = [[INSERT INTO visitPlace VALUES(NULL,']]..locationGlobal..[[')]]         db:exec(insertionTable)         for row in db:nrows("SELECT \* FROM visitPlace") do             local text = row.location             local t = display.newText(text, 450, 120\*row.id, native.systemFont, 40)             t:setFillColor(1,0,1)         end         local label1 = display.newText( "Submitted", 180, 30, native.systemFontBold, 20 )         label1:setFillColor( 190/255, 190/255, 1 )     end end

Please post the text of the error message and the current code.

Rob

This is my complete code. I create multiple boxes and implement similar functions in each

local widget = require("widget") require "sqlite3" --Open data.db. If the file doesn't exist it will be created local path = system.pathForFile("testUser.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 local tablesetup = [[CREATE TABLE IF NOT EXISTS visitPlace (id INTEGER PRIMARY KEY autoincrement, location, area, arrivalTime, departTime, eventAttended);]] print(tablesetup) db:exec( tablesetup ) \_W = display.viewableContentWidth \_H = display.viewableContentHeight background = display.newImage ("Default-568h@2x.png"); background.x = \_W/2;background.y = \_H/2; background:toBack(); --Inserting Sample Values --local insertionTable = [[INSERT INTO visitPlace VALUES(NULL,'India Gate','Delhi','8:00am','10:30pm','Meeting' )]] -- db:exec(insertionTable) --local insertionTable = [[INSERT INTO visitPlace VALUES(NULL,'Lotus Temple','Delhi','2:00pm','5:00pm','Relaxing' )]] -- db:exec(insertionTable) local function textListenerArea( event ) if ( event.phase == "began" ) then -- user begins editing defaultField event.target.text = '' print(location) print( event.text ) elseif ( event.phase == "ended" ) then -- do something with defaultField text areaGlobal = tostring( event.target.text ) print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) end end local function textListenerEventAttended( event ) if ( event.phase == "began" ) then -- user begins editing defaultField event.target.text = '' print( event.text ) elseif ( event.phase == "ended" or event.phase == "submitted") then -- do something with defaultField text eventAttendedGlobal = tostring( event.target.text) print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) end end local function textListenerArrival( event ) if ( event.phase == "began" ) then -- user begins editing defaultField event.target.text = '' print(location) print( event.text ) elseif ( event.phase == "ended" ) then -- do something with defaultField text arrivalTimeGlobal = tostring( event.target.text) print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) end end local function textListenerDepart( event ) if ( event.phase == "began" ) then -- user begins editing defaultField event.target.text = '' print(location) print( event.text ) elseif ( event.phase == "ended" ) then -- do something with defaultField text departGlobal = tostring( event.target.text) print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) -- elseif ( event.phase == "submitted" ) then -- departGlobal = tostring( event.target.text) --departGlobal = "default" end end local function textListenerLocation( event ) if ( event.phase == "began" ) then -- user begins editing defaultField event.target.text = '' print(location) print( event.text ) elseif ( event.phase == "ended") then -- do something with defaultField text locationGlobal = tostring( event.target.text) print( event.target.text ) elseif ( event.phase == "editing" ) then print( event.newCharacters ) print( event.oldText ) print( event.startPosition ) print( event.text ) cationGlobal =tostring( event.target.text) end end local function SubmitEvent( event ) -- local label = display.newText( location, 180, 30, native.systemFontBold, 20 ) -- label:setFillColor( 190/255, 190/255, 1 ) if "ended" == event.phase then local insertionTable = [[INSERT INTO visitPlace VALUES(NULL,']]..locationGlobal..[[',']]..areaGlobal..[[',']]..arrivalTimeGlobal..[[',']]..departTimeGlobal..[[',']]..eventAttendedGlobal..[[' )]] db:exec(insertionTable) for row in db:nrows("SELECT \* FROM visitPlace") do local text = row.location local text2 = row.area local text3 = row.event local t = display.newText(text, 450, 120\*row.id, native.systemFont, 40) t:setFillColor(1,0,1) local t2 = display.newText(text2, 450, 120\*row.id, native.systemFont, 40) t2:setFillColor(1,0,1) local t3 = display.newText(text3, 450, 120\*row.id, native.systemFont, 40) t3:setFillColor(1,0,1) end local label1 = display.newText( "Submitted", 180, 30, native.systemFontBold, 20 ) label1:setFillColor( 190/255, 190/255, 1 ) end end function background:tap( event ) native.setKeyboardFocus(nil) -- body end local label1 = display.newText( "Location", 180, 50, native.systemFontBold, 30 ) label1:setFillColor( 0, 0, 0 ) local locationTxtbox = native.newTextField(180,140,280,100) locationTxtbox.size = 34 locationTxtbox:addEventListener("userInput",textListenerLocation) local label2 = display.newText( "Area", 180, 250, native.systemFontBold, 30 ) label2:setFillColor( 0, 0, 0 ) local areaTxtbox = native.newTextField(180,340,280,100) areaTxtbox.size = 34 areaTxtbox:addEventListener("userInput",textListenerArea) local label3 = display.newText( "Arrival Time" , 180, 450, native.systemFontBold, 30 ) label3:setFillColor( 0, 0, 0 ) local arrivalTimeTxtbox = native.newTextField(180,540,280,100) arrivalTimeTxtbox.size = 34 arrivalTimeTxtbox:addEventListener("userInput",textListenerArrival) local label4 = display.newText( "Departure Time", 180, 650, native.systemFontBold, 30 ) label4:setFillColor( 0, 0, 0 ) local destTimeTxtbox = native.newTextField(180,740,280,100) destTimeTxtbox.size = 34 destTimeTxtbox:addEventListener("userInput",textListenerDepart) local label5 = display.newText( "Event Attended", 180, 850, native.systemFontBold, 30 ) label5:setFillColor( 0, 0, 0 ) local eventTxtbox = native.newTextField(180,940,280,100) eventTxtbox.size = 34 eventTxtbox:addEventListener("userInput",textListenerEventAttended) local submitButton = widget.newButton { label = "Submit", onEvent = SubmitEvent, shape = "roundedRect", width = 200, height = 50, cornerRadius = 2 } submitButton.x = 180 submitButton.y = 1050 background:addEventListener("tap",background) Runtime:addEventListener( "system", onSystemEvent )

Error Message : 

Runtime Error

.\main.lua:155:attempt to concatenate global ‘eventAttendedGlobal’ (a nil value)

You’ve been saying “same error”.  But the error above is different:

.\main.lua:155:attempt to concatenate global ‘eventAttendedGlobal’ (a nil value)

attempt to concatenate global locationGlobal (a nil value)"

Are totally different errors.  In the case of the 2nd one, you didn’t point us to the line number but in this case they are the same line number.   In the 2nd message, you can clearly see the error is happening with a different variable.  In your first report, locationGlobal was the cause.  You’ve fixed it, because now eventAttendedGlobal is now causing the error.   In both cases, it’s a nil value, but when you tell us it’s the same error and I know the code I provided fixed it, it’s very hard to trouble shoot.  You need to learn to read the entire message.  Find the line number, the variable and the cause of the error.  All are right there for you.

Now that said I don’t see why you’re getting this error unless you don’t fill the field out.  You do however have this error:

Attempt to concatenate global ‘departTimeGlobal’ (a nil value)

But in that case your saving your text to “departGlobal” not “departTimeGlobal”.    I personally would not use the ended/submit phases to collect your data.  When you submit your form, just access the object’s .text attribute, perhaps something like this:

local function SubmitEvent( event ) -- local label = display.newText( location, 180, 30, native.systemFontBold, 20 ) -- label:setFillColor( 190/255, 190/255, 1 )     if "ended" == event.phase then         local insertionTable = [[INSERT INTO visitPlace VALUES(NULL,']]..locationTextbox.text..[[',']]..areaTextbox.text..[[',']]..arrivalTimeTextbox.text..[[',']]..departTimeTextbox.text..[[',']]..eventTextbox.text..[[' )]]           db:exec(insertionTable)           for row in db:nrows("SELECT \* FROM visitPlace") do             local text = row.location             local text2 = row.area             local text3 = row.event             local t = display.newText(text, 450, 120\*row.id, native.systemFont, 40)             t:setFillColor(1,0,1)             local t2 = display.newText(text2, 450, 120\*row.id, native.systemFont, 40)             t2:setFillColor(1,0,1)             local t3 = display.newText(text3, 450, 120\*row.id, native.systemFont, 40)             t3:setFillColor(1,0,1)         end         local label1 = display.newText( "Submitted", 180, 30, native.systemFontBold, 20 )         label1:setFillColor( 190/255, 190/255, 1 )     end end

but for this to work, you would need to move this function just above where you define the button since it references the fields directly and where the submit function is, those fields are not defined.  This also gets out out of using a bunch of global variables which are considered bad unless you’re experienced and you know what you’re doing.

Rob