У меня проблемы с отправкой информации в мою базу данных в Corona SDK Lua. Ранее я использовал метод $ _GET, но мне сказали, что это небезопасно, поэтому я переключился на _POST, и теперь я продолжаю получать инструкцию else, но в моем журнале консоли не отображаются ошибки.
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
endlocal 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
Задача ещё не решена.
Других решений пока нет …