php - Ajax post json response issue -


i have issue ajax response. using custom query fetch result database. json response shows null value while query running successfully. here code:

if(isset($_post)){  $arr = array(); //$query = mysql_query(" insert login (user,pass) values ('".$_post['firstname']."','".$_post['lastname']."') ") or die('test');  $query = mysql_query(" select *  login user = '".$_post['firstname']."' && pass = '".$_post['pass']."' ") or die('test'); $rows = mysql_num_rows($query);      while($fetch = mysql_fetch_array($query))     {         if($fetch)         {                 $_session['id']= $fetch['id'];                 $arr['id'] = $_session['id'];          }         else         {             $arr['failed']= "login failed try again....";          }  }  echo json_encode($arr);  } 

@amandhiman did not use of if statement in while

if($fetch)     {             $_session['id']= $fetch['id'];             $arr['id'] = $_session['id'];      } 

the mention code works

    if($rows>0)     {         while($fetch = mysql_fetch_array($query))         {              $_session['id']= $fetch['id'];              $arr['id'] = $_session['id'];         }     }else         {             $arr['failed']= "login failed try again....";          } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -