title: return mysql echo as error in ajax
body: <p>i am creating login page with ajax.when user name and pass is wrong it should display error and when pass is right it should redirect to another page.but here in both case success function is called..     </p>
  
  <pre><code>&lt;script&gt;
      $(document).ready(function()
      {
  
  
      $("#simple-post").click(function()
      {
          $("#ajaxform").submit(function(e)
          {
              $("#simple-msg").html("&lt;img src='loading.gif'/&gt;");
              var postData = $(this).serializeArray();
              var formURL = $(this).attr("action");
  
              $.ajax(
              {
                  url : formURL,
                  type: "POST",
                  data : postData,
                  success:function(data, textStatus, jqXHR) 
                  {
                  alert(data.status);
                  $("#simple-msg").html('&lt;pre&gt;&lt;code class="prettyprint"&gt;'+data+'&lt;/code&gt;&lt;/pre&gt;');
  
  
                  },
                  error: function(jqXHR, textStatus, errorThrown) 
                  {
                      $("#simple-msg").html('&lt;pre&gt;&lt;code class="prettyprint"&gt;AJAX Request Failed&lt;br/&gt; textStatus='+textStatus+', errorThrown='+errorThrown+'&lt;/code&gt;&lt;/pre&gt;');
                  }
              });
              e.preventDefault(); //STOP default action
          });
  
          $("#ajaxform").submit(); //SUBMIT FORM
      });
  
      });
      &lt;/script&gt;
  </code></pre>
  
  <p>this is php</p>
  
  <pre><code>&lt;?php
  ob_start();
  
  include 'CUserDB.php';
  
  session_start(); 
  include 'config.php';
  $myusername=$_POST['txtusername']; 
  $mypassword=$_POST['txtpassword']; 
  $myusername = stripslashes($myusername);
  $mypassword = stripslashes($mypassword);
  $myusername = mysql_real_escape_string($myusername);
  $mypassword=mysql_real_escape_string($mypassword);      
  
  $qry = "SELECT UserName,Type_user FROM login WHERE UserName = '".$myusername."' AND password = '".$mypassword."' ";
  
  $result = mysql_query($qry) or die ("Query failed");
  
  $UserData = mysql_fetch_array($result);
  
      if($UserData['UserName'] != '')
  
          {
              session_start(); 
  
               $_SESSION['UserId'] = $myusername;
  
          $typ = $UserData['Type_user'];
  
  
  
      if   ( $typ == "Dealer")
      { 
   header('location:Dealer/EditLoginDetails.php');  
  
  
      }
      else if     ($typ == "Individual")
      {
           header('location:/Dealer/EditLoginDetails.php');  
  
      }
      else 
      {
          header('location:/Builder/managep.php'); 
      }
  
  
  
  
          }
     else 
  
      { 
      echo " wrong username or password";
  
  
      }
  
  ?&gt;
  </code></pre>
  
  <p>i want to display wrong username pass if not success..how to do this please i am new in ajax</p>