Я застрял здесь с этой проблемой весь день, и все другие варианты, которые я имею в виду, давно прошли. Я создал систему регистрации и регистрации для своего приложения в социальной сети. Я перестала работать над приложением в течение нескольких месяцев, и теперь я продолжаю получать сообщение об ошибке. Проблема находится на странице регистрации.
Я ввел все учетные данные, а затем нажал кнопку регистрации, и он сообщил мне об 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 forward declared
username.placeholder = "Username"
screenGroup:insert(username)
pw = native.newTextField( 160, 205,180, 30 ) -- take the local off since it forward declared
pw.isSecure = true
pw.placeholder = "Password"
screenGroup:insert(pw)
pw2 = native.newTextField( 160, 250,180, 30 ) -- take the local off since it 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 forward declared
email.placeholder = "E-mail"
screenGroup:insert(email)
Любая помощь?!?
Вам нужно заменить строку
echo"successful.";
с
echo "success";
в signup.php. Ответ от php scipt будет сохранен в event.response
поэтому, когда вы сравниваете обе строки, они совпадают.
Примечание: инструкция json.prettify( event )
возвращает string
. Чтобы вывести его на консоль, используйте функцию print
.