Your php asks for password and password2
The database has a column name “pw” and that’s fine. But your $_GET[]'s are looking for “password” and “password2”. What you put in your URL has to match what you’re looking for in the $_GET[] array.
You can rename the variables.
Now finally handling the results:
local function networkListener( event ) if ( event.isError ) then print( "Network error. ") else end end
This looks to see if there is a network error such as a time out or a page not found type error. Any output from your script, like “success”, “user exists” is a successful network request and event.isError will be false and the “else” block will execute which does nothing.
In side the “else” block you need to test for the output from the PHP script. Perhaps something like:
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 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
You will have to figure out what code to put in the blocks. I put in some comments with some suggestions.
Rob
I don’t understand the first part of your corrections.
Which part? the ordering of the functions?
The change to the URL?
URL encoding?
Handing the result?
You said this function has to be written in the code above but they are two different functions
It is called scoping you code is read from top to bottem. If you call a local function before it is declared you will get it an error
Your code you supplied above has two functions:
local function userRegister( event ) local function networkListener( event )
and I’m giving you a 3rd function you need:
local function urlencode( str )
In Lua/Corona the order of functions matter. userRegister tries to call networkListener (via. the network.request call), but networkListener doesn’t exist at that point, so nil gets passed to the handler. Your network.request() will never execute the call back. Your functions have to be in this order:
local function urlencode( event ) local function networkListener( event ) local function userRegister( event )
Technically urlencode and networkListener could swap order, but networkListener absolutely has to be defined in your code before userRegsiter.
Rob
I am getting this error
register.lua:24: attempt to call global 'url\_encode' (a nil value) stack traceback: C:\Users\user\Documents\Corona Projects\app\register.lua:24: in func tion '\_onEvent' ?: in function '?' ?: in function \<?:449\> ?: in function \<?:221\>
That function is not build inhttps://coronalabs.com/blog/2014/11/11/tutorial-encoding-urls-for-network-usage/Put it on top
My mistake, take out the _ in url_ecode.
Rob
Thanks it works , but I did this
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 local alert = native.showAlert( "You are not connected to the Internet. ", { "Try again"}, onComplete ) end end end
And it’s not taking me to the login page , but the info is going to the database (sign up is successful)
If you don’t get success you cannot assume they are not connect to the internet.
But the info gets sent to the database . Doesn’t that mean the it’s connected to the internet
No. If you get a “user exists”, you’re connected to the Internet just fine. The user needs to use a different username and/or email
You have lots of other echos like if the user already exists or passwords don’t match you should show those errors to the user.
What I don’t get is , when I click register the information gets sent to database correctly but the screen doesn’t go to the login page and the console says something went wrong . try again
can you copy and paste the message from the console log to here?
Something went wrong. Try again.