Check for empty fields

But I have another problem . I get the error message but the information still gets sent to the database . For example if I put in a username and click register the username field gets filled in but the other fields are empty 

You are going to need to share some updated code

local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") -- forward declare the text fields local json = require("json") local username local password local email local function emptyFields( event ) if ( username.text == "" or password.text == "" or password2.text == "" or email.text == "" ) then local alert = native.showAlert( "Error", "Fill in all fields .", { "Try again" } ) end end local function urlencode(str) if (str) then str = string.gsub (str, "\n", "\r\n") str = string.gsub (str, "([^%w])", function (c) return string.format ("%%%02X", string.byte(c)) end) str = string.gsub (str, " ", "+") end return str end local function networkListener( event ) if ( event.isError ) then print( "Network error.") else if event.response == "success" then print("Success! We are now registered!") -- put the code here to go to where the user needs to be -- after a successful registration composer.gotoScene("login") else -- put code here to notify the user of the problem, perhaps -- a native.alert() dialog that shows them the value of event.response -- and take them back to the registration screen to let them try again end end end local function userRegister( event ) if ( "ended" == event.phase ) then if emptyFields() == true then else local URL = "http://hash.comxa.com/register.php?Register=1&username=" .. username.text .. "&password=" .. password.text .. "&password2=" .. password2.text .. "&email=" .. urlencode( email.text ) network.request(URL, "GET", networkListener) end end end local function loginLink( event ) if ( "ended" == event.phase ) then composer.gotoScene("login") end end function scene:create(event) local screenGroup = self.view display.setDefault("background", 0, 3, 5) local icon = display.newImage("hash\_opt.png", 160, 70) screenGroup:insert(icon) local myText = display.newText( "#Hash", 160, 150, native.systemFontBold, 26 ) myText:setFillColor( 1, 2, 4.5 ) username = native.newTextField( 160, 200, 180, 30 ) -- take the local off since it's forward declared username.placeholder = "Username" screenGroup:insert(username) password = native.newTextField( 160, 250,180, 30 ) -- take the local off since it's forward declared password.isSecure = true password.placeholder = "Password" screenGroup:insert(password) password2 = native.newTextField( 160, 300,180, 30 ) -- take the local off since it's forward declared password2.isSecure = true password2.placeholder = "Confirm Password" screenGroup:insert(password2) email = native.newTextField( 160, 350, 180, 30 ) -- take the local off since it's forward declared email.placeholder = "E-mail" screenGroup:insert(email) local Button = widget.newButton( { shape = "roundedRect", left = 70, top = 400, id = "Register", label = "Register", onEvent = userRegister } ) screenGroup:insert(Button) local Button2 = widget.newButton( { left = 70, top = 460, id = "Loginhere", label = "Login here", onEvent = loginLink } ) screenGroup:insert(Button2) end function scene:show(event) end function scene:hide(event) end function scene:destroy(event) end scene:addEventListener("create", scene) scene:addEventListener("show", scene) scene:addEventListener("hide", scene) scene:addEventListener("destroy", scene) return scene

Empty fields is not returning anything.

But it’s showing the native.showAlert

local function emptyFields( event ) if ( username.text == "" or password.text == "" or password2 == "" or email.text == "" ) then local alert = native.showAlert( "Please fill in all fields .", emptyFields ) return true else return false end end

It should look like this

local function emptyFields( event ) if ( username == "" or password == "" or email == "" ) then local alert = native.showAlert( "Please fill in all fields .", emptyFields ) end end

I you are using text fields or box you may need to do this

local function emptyFields( event ) if ( username.text == "" or password.text == "" or email.text == "" ) then local alert = native.showAlert( "Please fill in all fields .", emptyFields ) end end

I am guessing emptyFields is a string value?

Please read docs for more info

https://docs.coronalabs.com/api/library/native/showAlert.html

I’m not getting any errors but it’s not showing anything 

Can you share some code?

local function emptyFields( event ) if ( username.text == "" or password.text == "" or password2 == "" or email.text == "" ) then local alert = native.showAlert( "Please fill in all fields .", emptyFields ) end end local function urlencode(str) if (str) then str = string.gsub (str, "\n", "\r\n") str = string.gsub (str, "([^%w])", function (c) return string.format ("%%%02X", string.byte(c)) end) str = string.gsub (str, " ", "+") end return str end local function networkListener( event ) if ( event.isError ) then print( "Network error. ") else if event.response == "success" then print("Success! We are now registered!") -- put the code here to go to where the user needs to be -- after a successful registration composer.gotoScene("login") else -- put code here to notify the user of the problem, perhaps -- a native.alert() dialog that shows them the value of event.response -- and take them back to the registration screen to let them try again end end end local function userRegister( event ) if ( "ended" == event.phase ) then local URL = "http://hash.comxa.com/register.php?Register=1&username=" .. username.text .. "&password=" .. password.text .. "&password2=" .. password2.text .. "&email=" .. urlencode( email.text ) network.request(URL, "GET", networkListener) end end

That’s the order that I have it in

Are username, password; and email text fields. What is emptyFields?

Their text fields 

Oh I see you need to replace local alert = native.showAlert( “Please fill in all fields .”, emptyFields ) with this local alert = native.showAlert( “Please fill in all fields .”, “message here” ) Also is emptyFields being called?

No I don’t know where to call it

I would do this

Would not format right
https://docs.google.com/document/d/11LNItMsWY4msOT7TalH7wGZMeZKPvh2VOCBfVJ4tMlI

can you pit it in code brackets ? 

Sorry I am on mobile, no code brackets. I just made a word docs really quick

 C:\Users\user\Documents\Corona Projects\app\register.lua:56: '\<name\> ' expected near '/' 

I am getting this error 

Try this url local URL = “http://hash.comxa.com/register.php?Register=1&username=” … username.text … “&password=” … password.text … “&password2=” … password2.text … “&email=” … urlencode( email.text )

Now i’m not getting an error : ERROR: C:\Users\user\Documents\Corona Projects\app\register.lua:15: native.s

howAlert() called with unexpected parameters

local alert = native.showAlert( "Please fill in all fields .", emptyFields )