I am trying to make sure the user does not input an existing username on the form but I am not getting it to display anything. This is part of my index file, I have included jquery.js and login.js in the header <td height="30"><label for="username">Username:</label></td> <td><input type="text" name="username" id="username" /> </td> <td><span id="usernameLoading"><img src="images/indicator.gif" alt="Ajax Indicator" /></span> <span id="usernameResult"></span></p></td> Code (markup): login.js $(document).ready(function() { $('#usernameLoading').hide(); $('#username').blur(function(){ alert("IT DID SOMETHING?"); $('#usernameLoading').show(); $.post("../functions/checkuser.php", { username: $('#username').val() }, function(response){ $('#usernameResult').fadeOut(); setTimeout("finishAjax('usernameResult', '"+escape(response)+"')", 400); }); return false; }); }); function finishAjax(id, response) { $('#usernameLoading').hide(); $('#'+id).html(unescape(response)); $('#'+id).fadeIn(); } //finishAjax Code (markup): checkuser.php <?php include("db.php"); $username = $_POST['username']; $username = trim(htmlentities($username)); echo check_username($username); // call the check_username function and echo the results. function check_username($username){ $result = "SELECT * FROM User WHERE Username='$username'"; $r = mysql_query($result); if(mysql_num_rows($r) >= 1){ return '<span style="color:#f00">Username Unavailable</span>'; } return '<span style="color:#0c0">Username Available</span>'; } ?> PHP: Thanks for any help, im really stuck here.
<?php include("db.php"); $username = $_POST['username']; echo $username.'<br />'; $username = trim(htmlentities($username)); echo check_username($username); // call the check_username function and echo the results. function check_username($username){ $result = "SELECT * FROM User WHERE Username='$username'"; $r = mysql_query($result); if(mysql_num_rows($r) >= 1){ return '<span style="color:#f00">Username Unavailable</span>'; } return '<span style="color:#0c0">Username Available</span>'; } ?> PHP: See whether the php file is ever called and whether the username is sent to it. (If you're going to write PHP code, learn to use FirePHP. It makes debugging a lot easier.)
Thanks, I got firebug already and now i've downloaded firephp but I think the problem might be in the jquery part of the file, see if I use the code above I never get an alert no matter what i did $('#username').blur(function(){ alert("IT DID SOMETHING?"); $('#usernameLoading').show(); $.post("../functions/checkuser.php", { Code (markup): But if I change to this i get the alert alert("IT DID SOMETHING?"); $('#username').blur(function(){\ $('#usernameLoading').show(); $.post("../functions/checkuser.php", { Code (markup):
I ran your code from post #1 (checkuser.php just echos that the user is okay) and it runs fine. All I had to add was the script tags (and I included the jQuery in the head of the document, not in a separate file) and and the link to jQuery.