Answer the question
In order to leave comments, you need to log in
Login verification is not performed. Where is the mistake?
Validation must be done on the user's side. When the focus is changed from the data entry field, the entered data should be validated and a warning about incorrectness should appear next to the field. If the login is entered incorrectly, nothing happens, and the data is quietly sent to the database. Regular expressions are written correctly.
registration.php
<div name="blockForm" class="form" id="reg">
<form name="regForm" action="registrationCheck.php" method="post">
<input type="text" name="login" class="reg_form" id="login" onblur="responseLog();" placeholder="Логин" required /><br />
<span id="errorLog" style="display: none">Логин введён некорректно! Логин должен начинаться со строчной или прописной буквы, он может содержать цифры или символы (._-\)</span>
<input type="submit" name="save" class="reg_form" id="save_reg" onclick="resetRegForm()" value="Сохранить" />
</form>
</div>
$(document).ready(function () {
function responseLog() {
$.ajax({
type: "POST",
url: "checkReg.php",
data: { action: 'login', user: $("#login").val() },
cache: false,
success: function (response) {
if (response == 'true') {
$("#errorLog").css("display", "block");
$("#errorLog").css("color", "red");
} else {
$("#login").css("background", "green");
};
}
});
};
function resetRegForm() {
$("#errorLog").css("display", "none");
};
});
<?php
$action = $_POST['action'];
$mysql = new mysqli ("localhost", "root", "", "yoursmilebase");
if ($action == "login") {
$row = $mysql->query("SELECT `login` FROM `users` WHERE `login` = '$action'");
if ($row) {
echo "true";
} else if (!preg_match("/^[a-zA-Z][a-zA-Z\d._-\\]{5,15}/", $action) || preg_match("/^(admin)/", $action)) {
echo "true";
} else {
echo "false";
};
}
$mysql->close;
?>
Answer the question
In order to leave comments, you need to log in
mysqli::query
Returns false on failure. If the SELECT, SHOW, DESCRIBE, or EXPLAIN queries succeed, mysqli_query() will return a mysqli_result object.
if ($row)
to true in the row, the condition is met, "true" is returned to the client. Sending an AJAX request goes to checkRegLog.php, and the verification code itself goes to checkReg.php
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question