What should be: 1. Js sends the information from the $login variable to the php server 2. Php connects the database and gets the password for this login from the accounts table 3. If the value is not found - the php server sends true , if it is found - false 4. It triggers a specific code in js, depending on the server response. Help me find the error.
Js:
$.post('check.php', {'login':login}, function(data) { if(data == "true"){ var div = document.querySelector("#login"); div.className = "true"; div.innerHTML = "Логин свободен!"; alogin = null; alogin = true; }else if(data == "false"){ var div = document.querySelector("#login"); div.className = "false"; div.innerHTML = "Логин занят!"; alogin = null; alogin = false; } }); Check.php
<?php $login = $_POST['login']; include ("db.php"); $result = mysql_query("SELECT password FROM accounts WHERE login='$login'",$db); if(empty($result)){ echo("true"); }else{ echo("false"); } ?>
$login,$resultanddataare equal to? - Regentlogin='$login'"- a potential place for a hack. - Stepan Kasyanenko