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