iRoot121 Posted May 4, 2014 Share Posted May 4, 2014 Hi, I'm trying to let JavaScript check if a givin user exist in the database. It seems that the _check-user.php always returns 0, but if I fill in a name that doesn't exist, and echo out the result variable in JS, the echo will return 1. Is there someone who could help me? JavaScript part: function checkUser() { $.post("_check_user.php", { 'username': document.getElementById("username").value }, function(result) { if (result == 1) { document.getElementById("checkUser").className = "succes"; document.getElementById("checkUser").innerHTML = "Name is available"; }else{ document.getElementById("checkUser").className = "errormsg"; document.getElementById("checkUser").innerHTML = "Name is not available!"; } }); } _check-user.php: <?php include("config.php"); $result = mysql_query("SELECT login FROM users WHERE login='".clean_string($_POST["username"])."'"); if(mysql_num_rows($result)>0){ echo 0; }else{ echo 1; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/288232-javascript-username-checker/ Share on other sites More sharing options...
jazzman1 Posted May 6, 2014 Share Posted May 6, 2014 Check first, what value you're sending to database. I'm pretty sureit's incorrect. <?php var_dump($_POST["username"]); exit; include("config.php"); Note: The original MySQL extension is now deprecated and it's not recommended to use for new development. Instead, use the MySQLi or PDO_MySQL extensions. Quote Link to comment https://forums.phpfreaks.com/topic/288232-javascript-username-checker/#findComment-1478335 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.