I am trying to sign up on my app using mysql. I don’t see problems on the server side but someone is definitely wrong On the front end side. I keep getting this error
local alert = native.showAlert( "Error Signing Up", "There was an error signing up.", { "Try again" } )
I don’t see problems with my code I haven’t used it in a couple years or so but it seems fine to me. Anyone notice something ?
local composer = require( "composer" )
local scene = composer.newScene()
local widget = require("widget")
-- forward declare the text fields
local json = require("json")
local username
local pw
local email
local function emptyFields(event)
if ( username.text == "" or pw.text == "" or pw2.text == "" or email.text == "" ) then
local alert = native.showAlert( "Error", "Fill in all fields .", { "Try again" } )
return true
else
return false
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 passwordMatch( event )
if ( pw.text ~= pw2.text ) then
local alert = native.showAlert( "Error", "Passwords do not match .", { "Try again" } )
return true
else
return false
end
end
local function networkListener( event )
if ( event.isError ) then
print( "Network error.")
else
if event.response == "success" then
-- put the code here to go to where the user needs to be
-- after a successful registration
composer.gotoScene("userarea")
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
local json = require("json")
json.prettify( event )
--print( "Handling the unhandled error", event.errorMessage )
local alert = native.showAlert( "Error Signing Up", "There was an error signing up.", { "Try again" } )
end
end
end
local function userRegister( event )
if ( "ended" == event.phase ) then
if emptyFields() == true then
else
if passwordMatch() == true then
else
local parameters = {}
parameters.body = "Register=1&username=" .. username.text .. "&pw=" .. pw.text .. "&email=" .. urlencode( email.text )
local URL = "http://localhost/hashmobile/process.php"
network.request(URL, "POST", networkListener, parameters)
end
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
local background = display.newImageRect("images.jpg",display.contentWidth,display.contentHeight)
background.x = display.contentCenterX
background.y = display.contentCenterY
screenGroup:insert(background)
myImage = display.newImage( "hash.png" )
-- position the image
myImage:translate( 160, 55 )
myText = display.newText( "#Hash", 160, 120, native.systemFontBold, 40 )
myText:setFillColor( 0, 5, 1.5 )
username = native.newTextField( 160, 160, 180, 30 ) -- take the local off since it's forward declared
username.placeholder = "Username"
screenGroup:insert(username)
pw = native.newTextField( 160, 205,180, 30 ) -- take the local off since it's forward declared
pw.isSecure = true
pw.placeholder = "Password"
screenGroup:insert(pw)
pw2 = native.newTextField( 160, 250,180, 30 ) -- take the local off since it's forward declared
pw2.isSecure = true
pw2.placeholder = "Confirm Password"
screenGroup:insert(pw2)
email = native.newTextField( 160, 290, 180, 30 ) -- take the local off since it's forward declared
email.placeholder = "E-mail"
screenGroup:insert(email)
text = display.newText( "Make your e-mail correct .", 170, 325, native.systemFontBold, 18 )
text:setFillColor( 2, 5, 1.5 )
local Button = widget.newButton(
{
shape = "roundedRect",
left = 70,
top = 350,
id = "Register",
label = "Register",
onEvent = userRegister,
fillColor = { default={ 1, 0.2, 0.5, 0.7 }, over={ 1, 0.2, 0.5, 1 } },
labelColor = { default={ 2, 4, 1.5 }, over={ 2, 5, 1.5, 2.2 } }
}
)
screenGroup:insert(Button)