Guest Posted February 20, 2012 Share Posted February 20, 2012 Ok, so basically what I want is the code to check the DB to see if a passworded username is already taken, then display an error if someone tries to post with that same name, but gives a wrong password for that name. What the code below does, is just that....except, even when you enter the correct password, it displays the error that the name has been taken...how can I fix this so when you enter the right password, it allows you to post? <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript" charset="utf-8"></script> <script language="javascript" type="text/javascript"> //<![CDATA[ $(document).ready(function(){ $("form#reply").submit(function() { var success = 0; var username = $('#user').attr('value'); $.ajax({ type: "GET", url: "checkusername.php", data: "username="+ username, success: function(r){ success = r; }, async:false }); if(success == 1) { alert("Username already taken."); return false; }else return true; }); }); //]]> </script> The checkusername.php code is: <?php require "database.php"; #check user on users table $user = fetch("SELECT COUNT(pid) FROM posts WHERE user = '".$_GET["username"]."'"); if(!$user || !isset($user)) echo '0'; if($user[0] > 0) echo '1'; else echo '0'; exit(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/257395-what-is-wrong-with-this-code/ Share on other sites More sharing options...
requinix Posted February 20, 2012 Share Posted February 20, 2012 You're not checking the password at all... Also, 1. Use POST. 2. Hash the password in your JavaScript before sending it in the URL and/or use SSL. Quote Link to comment https://forums.phpfreaks.com/topic/257395-what-is-wrong-with-this-code/#findComment-1319283 Share on other sites More sharing options...
Guest Posted February 20, 2012 Share Posted February 20, 2012 Could you modify it for me? Not really sure what to do...sorry. Quote Link to comment https://forums.phpfreaks.com/topic/257395-what-is-wrong-with-this-code/#findComment-1319286 Share on other sites More sharing options...
requinix Posted February 20, 2012 Share Posted February 20, 2012 Who wrote the original code? Quote Link to comment https://forums.phpfreaks.com/topic/257395-what-is-wrong-with-this-code/#findComment-1319290 Share on other sites More sharing options...
AyKay47 Posted February 21, 2012 Share Posted February 21, 2012 Could you modify it for me? Not really sure what to do...sorry. We will help you to modify the code yourself. However we do not provide free code. Required gave you some pointers, start there. Quote Link to comment https://forums.phpfreaks.com/topic/257395-what-is-wrong-with-this-code/#findComment-1319416 Share on other sites More sharing options...
Guest Posted February 21, 2012 Share Posted February 21, 2012 Well where do I start? Quote Link to comment https://forums.phpfreaks.com/topic/257395-what-is-wrong-with-this-code/#findComment-1319417 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.