Lua和PHP系统不工作

问题描述:

我正在创建一个需要用户登录的应用程序。当我点击登录按钮时,我只是得到else语句。我检查了我的控制台日志,但没有显示,没有错误。我尝试了很多次,并且在Corona SDK论坛上问过,但没有任何帮助。这是我的代码。Lua和PHP系统不工作

login.lua:

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

local function registerLink(event) 
if ("ended" == event.phase) then 
    composer.gotoScene("register") 

end 
end 

的login.php:

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

       $sql = "SELECT * FROM users where username = '" . $username . "' and pw = '" . $pw . "'"; 
        $result = mysqli_query($con, $sql); 
        $count = mysqli_num_rows($result); 

       if($count == 1){ 

       $_SESSION['logged in'] = true; 

       } 
       else 
       { 
       echo"username or password is incorrect."; 
       } 
} 
+0

为什么地球上你会同时使用php和lua?只用一个或另一个。 – mopsyd

+0

因为我正在构建一个社交应用程序 – user7327480

+0

PHP是后端 – user7327480

你你做连接之前,需要设置标题。尝试

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 headers = {} 

    headers["Content-Type"] = "application/x-www-form-urlencoded" 
    headers["Accept-Language"] = "en-US" 

    parameters.headers = headers 

    local URL = "http://hash.comxa.com/login.php" 
    network.request(URL, "POST", networkListener, parameters) 

end 
end 
end