PHP Lua registration and login

I am having some problems registering and logging in to my app . When I enter the credentials to sign up, I get 

Error signing up Registration successful

It look like there is an error with my corona sdk . The registration successful comes from my PHP code and not the Lua code. The credentials I enter go into the database and I can login with them . But when I sign up I get the message above . Please help .

registration.php:

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 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 local alert = native.showAlert( "Network Error . Check Connection", "Connect to Internet", { "Try again" } ) 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("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 json = require("json") json.prettify( event ) local alert = native.showAlert( "Error Signing Up", event.response, { "Try again" } ) end end end local function userRegister( event ) if ( "ended" == event.phase ) then if passwordMatch() == true then else local parameters = {} parameters.body = "Register=1&username=" .. username.text .. "&pw=" .. pw.text .. "&pw2=" .. pw2.text .. "&email=" .. urlencode( email.text ) local URL = "http://hash.x10host.com/cgi-bin/hash/signup.php" network.request(URL, "POST", networkListener, parameters) end end end local function loginLink( event ) if ( "ended" == event.phase ) then composer.gotoScene("login") end end

signup.php:

$con = mysqli\_connect("localhost", "username", "password", "database"); if(isset($\_POST['Register'])) { if (empty($\_POST["username"])) { echo"Fill in username to sign up"; } else { if (empty($\_POST["pw"])) { echo"Fill in password to sign up"; } else { if (empty($\_POST["pw2"])) { echo"Confirm password to sign up"; } else { if (empty($\_POST["email"])) { echo"Fill in email to sign up"; } else { if ($\_POST['pw'] == $\_POST['pw2']) { $username = mysqli\_real\_escape\_string($con, $\_POST["username"]); $pw= mysqli\_real\_escape\_string($con, $\_POST["pw"]); $pw2= mysqli\_real\_escape\_string($con, $\_POST["pw2"]); $email = mysqli\_real\_escape\_string($con, $\_POST["email"]); $result = mysqli\_query($con ,"SELECT \* FROM users WHERE username='" . $username . "'"); if(mysqli\_num\_rows($result) \> 0) { echo "Username exists . \<a href= index.php\>Try again\</a\>\<br /\> "; } else { $result2 = mysqli\_query($con ,"SELECT \* FROM users WHERE email='" . $email. "'"); if(mysqli\_num\_rows($result2) \> 0) { echo "Email exist. \<a href= index.php\>Try again\</a\>\<br /\> "; } else { $pw = password\_hash($pw, PASSWORD\_BCRYPT, array('cost' =\> 14)); $sql = "INSERT INTO users (username, pw, email) VALUES('" . $username . "', '" . $pw . "', '" . $email . "')"; if(mysqli\_query($con, $sql)){ // if insert checked as successful echo username and password saved successfully echo"Registration successful ."; }else{ echo mysqli\_error($con); } } } } else{ echo "The passwords do not match."; // and send them back to registration page } } }}}}

The picture I attached is what I get at the registration page.

Thank you for the help 

Your PHP script outputs the string “Registration successful” in this line of code:

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo"Registration successful .";

But your Corona/Lua script is looking for the string “success” to determine if the script was successful or not. I don’t see where the PHP script ever outputs the string “success”.

 if event.response == "success" then --\<------- here is where you test for the string "success" -- 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 json = require("json") json.prettify( event ) local alert = native.showAlert( "Error Signing Up", event.response, { "Try again" } ) end

I noted with a comment above where you’re testing for the string success otherwise you show your failure dialog.

Rob

I just changed my code to this 

 if event.response == "sql" then --\<------- here is where you test for the string "success"

and the same thing is happening 

Why would you do that?

The string being returned is “Registration successful .” (note the space between successful and the period)

Your PHP script never outputs the string “sql”.

Rob

Curious, does your code save the username and pw to the database?

If it doesn’t, then…

I’ve got something similar, but it’s in deprecated php5 I think. You may try something similar though. I had to hack my way through the php and mysql when I did this, which is now mysqli

This worked for me though

 mysql\_query("INSERT INTO `databaseName`.`databaseUserTable` (`ID`, `UserName`) VALUES (NULL, '$UserName')") or die(mysql\_error());

Your path for the database  to insert into may be incomplete, I’m not sure, the php syntax is so different.

Hope this helps,

Nail

I have this in my PHP now and the same thing is happening .

echo"success.";

Okay I fixed it 

Your PHP script outputs the string “Registration successful” in this line of code:

&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo"Registration successful .";

But your Corona/Lua script is looking for the string “success” to determine if the script was successful or not. I don’t see where the PHP script ever outputs the string “success”.

 if event.response == "success" then --\<------- here is where you test for the string "success" -- 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 json = require("json") json.prettify( event ) local alert = native.showAlert( "Error Signing Up", event.response, { "Try again" } ) end

I noted with a comment above where you’re testing for the string success otherwise you show your failure dialog.

Rob

I just changed my code to this 

 if event.response == "sql" then --\<------- here is where you test for the string "success"

and the same thing is happening 

Why would you do that?

The string being returned is “Registration successful .” (note the space between successful and the period)

Your PHP script never outputs the string “sql”.

Rob

Curious, does your code save the username and pw to the database?

If it doesn’t, then…

I’ve got something similar, but it’s in deprecated php5 I think. You may try something similar though. I had to hack my way through the php and mysql when I did this, which is now mysqli

This worked for me though

 mysql\_query("INSERT INTO `databaseName`.`databaseUserTable` (`ID`, `UserName`) VALUES (NULL, '$UserName')") or die(mysql\_error());

Your path for the database  to insert into may be incomplete, I’m not sure, the php syntax is so different.

Hope this helps,

Nail

I have this in my PHP now and the same thing is happening .

echo"success.";

Okay I fixed it