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'
        }

   ?>  
user2013
  • 538
  • 5
  • 14
  • 1
    just replace all fields, unless you need to record where a change was made. –  Mar 31 '13 at 01:21
  • 1
    Have you tried double equal signs instead of triple equal? `==` vs `===`. In these instances, I don't see a reason to check the `type`, and that may be what's causing the issue.The difference between double and triple equals: http://stackoverflow.com/questions/80646/how-do-the-equality-double-equals-and-identity-triple-equals-comparis – Luke Shaheen Mar 31 '13 at 01:23

1 Answers1

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
}
Ares
  • 5,905
  • 3
  • 35
  • 51
  • I have to check the 'text' type data as 'user_biography'. Is that "strcasecmp" is usefull ?? – user2013 Mar 31 '13 at 02:08
  • Then just change 'user_name' for 'user_biography'. If it returns anything but 0 it means the value was changed. – Ares Mar 31 '13 at 02:12
  • @SabbirHossain Glad to help. If this is the answer to your question, then mark it as such for future reference. – Ares Mar 31 '13 at 02:21