0

I'm working on a jQuery-powered registration form, and I'm checking all the input with jQuery, and the only thing left is to see if a user is choosing an already-registered name.

Here's my Ajax request:

 $.ajax({
   type: "POST",
   url: "check_user.php",
   data: "username="+username,
   success: function(){
     errors.push('Your username is taken.');
   }
 });

And check_user.php:

<?php
include_once('../lib/config.php');

$username = $_POST['username'];
$query = mysql_query("SELECT * FROM `users` WHERE `username` = '$username'");
if(mysql_num_rows($query) == 1) {
    header("HTTP/1.1 200 OK");
}

?>

I know the errors.push(); works, because when I was trying to figure out what was wrong with the Ajax request earlier, the 'Username is taken' message was showing up on my registration page whenever I click 'Register'. Now nothing is showing up at all.

Here's all my whole registration page: http://pastebin.org/66815

apaderno
  • 28,547
  • 16
  • 75
  • 90
Andrew
  • 12,172
  • 16
  • 46
  • 61
  • do the error or complete events get fired if you wire them up? – Goyuix Dec 20 '09 at 04:41
  • 2
    Once you get the $.ajax usage figured out, and based on the check_user.php snippet shown here, I suggest looking at coding to prevent an SQL injection on the PHP request side. SEE Prepared statments http://stackoverflow.com/questions/60174/best-way-to-stop-sql-injection-in-php/60496#60496 and filtering http://stackoverflow.com/questions/60174/best-way-to-stop-sql-injection-in-php/60442#60442 All the best. – micahwittman Dec 20 '09 at 04:59

1 Answers1

2

The file (signup.php) is located at C:\xampp\htdocs\register\user\signup.php

I was using .htaccess and RewriteRule ^signup user/signup.php and viewing it at http://localhost/signup. When I removed that RewriteRule and got to http://localhost/register/user/signup.php, everything worked fine.

So I changed url: "check_user.php" to "url: user/check_user.php" and it all works fine. I didn't know .htaccess was that badass.

apaderno
  • 28,547
  • 16
  • 75
  • 90
Andrew
  • 12,172
  • 16
  • 46
  • 61