duan32342 2016-09-11 16:25
浏览 53

登录系统Lua

I am having problems sending info into my database in Corona SDK Lua . I was previously using the $_GET method but I was told that it's not safe so I switched to _POST and now i keep getting the else statement but my console log isn't showing any errors .

register.php:

// Check connection
             if ($con->connect_error) {
             die("Check connection.");
                }

                if(isset($_POST['Register'])) {
            if ($_POST['pw'] == $_POST['pw2']) {
                 $username = mysqli_real_escape_string($con, $_POST["username"]);
                 $pw= mysqli_real_escape_string($con, $_POST["pw"]);
                 $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 exist";
                    } else {

                       $result2 = mysqli_query($con ,"SELECT * FROM users WHERE email='" . $email. "'");

                       if(mysqli_num_rows($result2) > 0)
                       {
                       echo "email exist";
                       } else {

               $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"success";
                       }else{
                       echo mysqli_error($con);
                       }   

        } } }
            }else{
            echo "The passwords do not match.";  // and send them back to registration page
            }

register.lua:

local function userRegister( event )
if ( "ended" == event.phase ) then
 if emptyFields() == true then  

 else

     if passwordMatch() == true then  

    else

    local URL = "http://hash.comxa.com/register.php?Register=1&username=" .. username.text .. "&pw=" .. pw.text .. "&pw2=" .. pw2.text .. "&email=" .. urlencode( email.text )        
    network.request(URL, "POST", networkListener)

end
end
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("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( "Error Signing Up", "There was an error signing up.", { "Try again" }  )

end
end
end
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并
    • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
    • ¥20 Java-Oj-桌布的计算