0

In my project, mysql table value need to be updated, so when user see his/her profile then he/she can update his/her profile, after click the 'update profile' button he/she would see a form which fill with previous data and then he may change his profile or not. I want to check if he/she update information or not, so I fetch that user information from database and check the present information that he/she enter, if values change, then store that changed value on other array and store only that changed information. So I use strcmp( str1, str2) function but it doesn't work, so I use "===" it works only for small data such as name, password etc. But I need also to check if he/she change his/her biography or not, I use that function but it doesn't work.

My code ::

  <?php
          $users = $user->user_info_by_id($object->id);  // get user's info from database

          foreach( $users as $user )  {  // 
            if( $user->user_name === $arrayValue['user_name'] )  // here $arrayValue['user_name'] is the recent info that user sent to update his profile 
                echo "<br /> value matched";   // it matched
            else {
                echo "<br /> value not matched";
            }

            if( $user->user_biography === $arrayValue['user_biography'] ) // it doesn't work, here 'user_biography' is 'text' type data in mysql database
                echo "<br /> value matched";
            else 
                echo "<br /> value not matched";  // answer is always 'value not matched'
        }

   ?>  
4

1 回答 1

1

strcasecmp should do the job. I know you mentioned on your answer that you tried strcmp and it didn't work but you did not mention or showed how you were using it.

Try:

if($user->user_biography === trim($arrayValue['user_biography']) != 0) {
   // user_name changed. 
 } else {
   //user_name did not change
}
于 2013-03-31T02:06:26.037 回答