1

I have problem with my code. I use jQuery post for confirm that the name of filter is free for use.

$.post('check-username.php', $("#myform").serialize(), function(data) {
    alert(data);
});

When I use alert to show content of data, everything is fine.

But I need something like that:

$.post('check-username.php', $("#myform").serialize(), function(data) {
if(data == 'ne'){
    alert('name allready taken');
}
});

But that wont work...

Here is my php code.

<?php
include("config.php");

$Sql = MySQL_Query("SELECT id FROM Filters where name = '".$_POST['name']."'");
if ( mysql_num_rows($Sql) != 0 ) {
   echo "ok";
}

else{
       echo "ne";
}
?>

Sorry for my english ;) Thanks for help

1 Answers1

0

The if statement looks ok.

And if it looks ok when you alert the data - perhaps there is additional whitespace before or after "ne" in your php page? Try adding an exit; statement after echo "no"; and see if that makes a difference.

becquerel
  • 1,131
  • 7
  • 11
  • You can get rid of those whitespaces. `data = data.replace(/^\s+|\s+$/g, ""); if(data=="ne")` should work – devnull69 Oct 08 '13 at 12:13