title: Ajax and php - login script
body: <p>I'm trying to do a login page, but I have an issue wit ajax method:</p>
  
  <pre><code> $("#login").click(function(){
  
          username=$("#user_name").val();
          password=$("#password").val();
           $.ajax({
              type: "POST",
              url: "login.php",
              data: {name : username, pwd : password},
              success: function(html){
                if( ($.trim(html)) =='true')
                {
                  $("#login_form").fadeOut("normal");
                          $("#shadow").fadeOut();
                          $("#profile").html("&lt;a href='logout.php' id='logout'&gt;Logout&lt;/a&gt;");
  
                }
                else
                {
                      $("#add_err").html("Wrong username or password");
                }
              },
              beforeSend:function()
                  {
                   $("#add_err").html("Loading...")
              }
          });
           return false;
      });
  </code></pre>
  
  <p><strong>login.php:</strong></p>
  
  <pre><code>&lt;?php  
  
   session_start();
  
   $username = $_POST['name'];
   //$username = $mysqli-&gt;real_escape_string($username);
   $password = ($_POST['pwd']);
   //$password = $mysqli-&gt;real_escape_string($password);
  
   $mysqli = mysqli_connect('localhost','root','','peer');
   $query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
   $result = mysqli_query($mysqli,$query)or die(mysqli_error());
   $num_row = mysqli_num_rows($result);
   $row=mysqli_fetch_array($result);
   if( $num_row &gt;=1 ) {
    echo 'true';
    $_SESSION['user_name']=$row['username'];
   }
   else{
   echo 'false';
   }
  ?&gt;
  </code></pre>
  
  <p>I'm posting to login.php username and password, but obviously get nothing back, when I tried execute only php script it works correct. A html object seems like is still <code>false</code>.
  Do you see any mistake here ??</p>
  
  <p>thanks</p>
  
  <p>EDIT!</p>