我整天都遇到这个问题,我想到的所有其他选择早已不复存在。我为我的社交网络应用创建了一个登录和注册系统。我可能已经停止了几个月的应用程序,现在我一直在收到错误。问题出在注册页面上。
我输入所有凭据,然后点击注册按钮,它告诉我Error signing up
,同时打印出告诉我从PHP端注册成功的语句Successful
。凭证虽然进入了数据库。我可以和他们一起登录。但是在注册页面注册成功时,我想进入登录页面登录。请帮帮我。
signup.php:
$con = mysqli_connect("localhost", "hashx10h_brandon", "bigman23", "hashx10h_hash");
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"successful .";
}else{
echo mysqli_error($con);
}
} } } else{
echo "The passwords do not match."; // and send them back to registration page
}
}
}}}}
Register.lua:
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
username = native.newTextField( 160, 160, 180, 30 ) -- take the local off since it's forward declared
username.placeholder = "Username"
screenGroup:insert(username)
pw = native.newTextField( 160, 205,180, 30 ) -- take the local off since it's forward declared
pw.isSecure = true
pw.placeholder = "Password"
screenGroup:insert(pw)
pw2 = native.newTextField( 160, 250,180, 30 ) -- take the local off since it's forward declared
pw2.isSecure = true
pw2.placeholder = "Confirm Password"
screenGroup:insert(pw2)
email = native.newTextField( 160, 290, 180, 30 ) -- take the local off since it's forward declared
email.placeholder = "E-mail"
screenGroup:insert(email)
任何帮助?!?
答案 0 :(得分:1)
您需要替换
echo"successful .";
带
echo "success";
在signup.php中。来自php scipt的响应将存储在event.response
中,因此当您比较两个匹配的字符串时。
注意:说明json.prettify( event )
会返回string
。要将其输出到控制台使用print
功能。