Registration form

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")

no when you run this what does

print( event.response)

say?

local function networkListener( event ) local json = require("json") print("share this") print("-----------------") print(json.prettify(event)) print("-----------------") 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

Replace your network lis with this

Nothing 

Nope still nothing

update this

local function userRegister( event ) if ( "ended" == event.phase ) then print("this is running") 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

let me know if you see “this is running”

It prints this is running

it says that

replace this

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 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

with 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 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

please note I updated the code above just now

Thank You it works now ! Thank to you too Rob !! :slight_smile:

By any chance do you know how to change my display name ?

go to https://developer.coronalabs.com/user

account info > edit

Thanks

Check out these links 

Corona SDK – Saving player score on server using PHP

https://arekzb.wordpress.com/2012/04/27/corona-sdk-saving-player-score-on-server-using-php/

Saving JSON from web to SQL Database

https://forums.coronalabs.com/topic/58690-saving-json-from-web-to-sql-database/

YouTube - Downloading JSON data from MySQL to Corona SDK

In this tutorial Dr. Burton explains how to connect to a remote database through php, convert the data to JSON and pass to a mobile app using Corona SDK. The data is then saved to a local SQLite database.

https://www.youtube.com/watch?v=iIeJEBQYA10

That kind of helped but I honestly think I don’t know what I’m doing . If I post what I have will you be able to tell me if i"m going down the right path

You have several things going on. Most importantly you’re network code isn’t working. But before  you get there, you have to understand the work flow.

You have two buttons:  one labeled “Register” and executes a function called “handleButtonEvent” when pressed. I’m assuming this function should take the values of username, password and email and do something to create a new user on the web server for this person.

The second button “Login” tries to go to a new scene called “login”.

It would help to understand what you want to happen each time one of these buttons are pressed, then the community can help straighten out the code.

Next is security. How well do you know PHP and MySQL to write the server scripts? Have you thought about how you intend to secure the user’s data? Login/Password credentials need to be well secured and how you secure things on the server impacts how you write the Corona code to match.

Rob

When the user clicks the register button the users info will go to the database I have setup . The login here button takes the user to a page where they can sign up . That works properly . But I need help with the registration button . When I first tried my network code it worked but It wasn’t using the url I have now , it was example.com and it outputed what was on the website which was good . But when the user signs up and if its successful I want them to go to the page and login . Can you help Me with this ?

Maybe something like:

-- forward declare the text fields local username local password local email 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: ", event.response ) else print( event.response ) end end local function handleButtonEvent( event ) if ( "ended" == event.phase ) then local URL = "http://web.web.com/yourscript.php?username=" .. urlencode( username.text ) .. "&password=" .. urlencode(password.text) .. "&email=" .. urlencode( email.text ) network.request(URL, "GET", networkListener) 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("icon\_opt.png", 160, 70) screenGroup:insert(icon) 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, 260,180, 30 ) -- take the local off since it's forward declared password.isSecure = true password.placeholder = "Password" screenGroup:insert(password) email = native.newTextField( 160, 320, 180, 30 ) -- take the local off since it's forward declared email.placeholder = "E-mail" screenGroup:insert(email) -- rest of your code

Now there are still major concerns with this.  First of all, you’re access http:// which is not secure. This script as I have it written will transmit the password in the clear and anyone snooping on your network will be easily able to grab the username and password.  THIS IS INCREDIBLY INSECURE.

How can you secure it?

  1. Don’t use obvious keys like “username”, “password” and "email

  2. Base64 encode the data before you transmit it and your script needs to know to base64 decode it. If you base64 encode it, you won’t need to URL encode it which is a benefit.

  3. Use https:// instead of http://. Your server must be set up to run SSL but at least the data is encrypted during its transmission to the server.

A more secure version of this, would be:

-- forward declare the text fields local mime = require("mime") local username local password local email local function networkListener( event ) if ( event.isError ) then print( "Network error: ", event.response ) else print( event.response ) end end local function handleButtonEvent( event ) if ( "ended" == event.phase ) then local URL = "https://web.web.com/yourscript.php?a=" .. mime.b64( username.text ) .. "&b=" .. mime.b64(password.text) .. "&c=" .. mime.b64( email.text ) network.request(URL, "GET", networkListener) 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("icon\_opt.png", 160, 70) screenGroup:insert(icon) 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, 260,180, 30 ) -- take the local off since it's forward declared password.isSecure = true password.placeholder = "Password" screenGroup:insert(password) email = native.newTextField( 160, 320, 180, 30 ) -- take the local off since it's forward declared email.placeholder = "E-mail" screenGroup:insert(email) -- rest of your code

But this assumes you have control over your script that’s going to handle the input and store the data into a database and you can use https://.  Here I used keys: a, b and c and all the data has been base64 encoded.  On the server side if you’re using PHP it would be something like:

\<?php $username = mysqli\_real\_escape\_string( base64\_decode( $\_GET["a"]) ); $password = mysqli\_real\_escape\_string( base64\_decode( $\_GET["b"]) ); $email = mysqli\_real\_escape\_string( base64\_decode( $\_GET["c"]) ); // rest of&nbsp; your script echo "Success" // or whatever you want to communicate back to the Corona App as event.response. ?\>

Now this could be even more secure by making sure you only store the password in a one way encryption such as an MD5 hash. The server should add some additional text to the password (called a salt) before it’s hashed.  Then when the user logs in, you pass in the password from the user, salt it, hash it and then compare to what’s in the database. You should never store user passwords in clear text.  And MD5 is considered minimal security. An SHA hash with larger encryption keys is more secure. Most hackers can bust an MD5 hash pretty quickly these days. That’s why adding a salt string is important.

If you don’t have control over the server script, then you will have to make your URL, key-value pairs, encoding match what the server expects.

Rob