I have been trying for a long time now to create a login system that works for my app but it hasn’t been working . I get no errors on my php side I only get the else statement on my Lua code . I’ve been checking for months now but I can’t find the problem . Can I get some help ? Thanks !
login.php :
\<?php $con = mysqli\_connect("mysql9.000webhost.com", "a2677272\_root", "bigman23", "a2677272\_hash"); session\_start(); // Check connection if ($con-\>connect\_error) { die("Check connection."); } $username = ($\_POST["username"]); $pw = ($\_POST["pw"]); if(isset($\_POST['Login'])) { $username = mysqli\_real\_escape\_string($con, $\_POST["username"]); $pw = mysqli\_real\_escape\_string($con, $\_POST["pw"]); $result = mysqli\_query($conn ,"SELECT \* FROM users WHERE username = '" . $username . "' "); if($result == 1){ $\_SESSION['logged in'] = true; echo"success"; } else { echo"username or password is incorrect."; } } ?\>
login.lua:
username = native.newTextField( 160, 200, 180, 30 ) -- take the local off since it's forward declared username.placeholder = "Username" screenGroup:insert(username) pw = native.newTextField( 160, 270,180, 30 ) -- take the local off since it's forward declared pw.isSecure = true pw.placeholder = "Password" screenGroup:insert(pw) local Button3 = widget.newButton( { shape = "roundedRect", left = 70, top = 320, id = "Login", label = "Login", onEvent = userLogin, fillColor = { default={ 0, 1, 4, 0.7 }, over={ 1, 0.5, 0.8, 4 } }, labelColor = { default={ 2, 4, 1.5 }, over={ 2, 5, 1.5, 2.2 } } } ) screenGroup:insert(Button3)
local json = require("json") local username local pw local function emptyFields( event ) if ( username.text == "" or pw.text == "" ) then local alert = native.showAlert( "Empty fields", "Fill in all fields .", { "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 alert = native.showAlert( "Error Logging In", "There was an error logging in.", { "Try again" } ) end end end local function userLogin( event ) if ( "ended" == event.phase ) then if emptyFields() == true then else local parameters = {} parameters.body = "Login=1&username=" .. username.text .. "&pw=" .. pw.text local URL = "http://hash.comxa.com/login.php" network.request(URL, "POST", networkListener, parameters) local headers = {} headers["Content-Type"] = "application/x-www-form-urlencoded" headers["Accept-Language"] = "en-US" parameters.headers = headers end end end