Jump to content

What Is Wrong With This Code?


Guest

Recommended Posts

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();
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.