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

   ?>  
2
  • 1
    just replace all fields, unless you need to record where a change was made. Commented Mar 31, 2013 at 1: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: stackoverflow.com/questions/80646/… Commented Mar 31, 2013 at 1:23

1 Answer 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
}
Sign up to request clarification or add additional context in comments.

3 Comments

I have to check the 'text' type data as 'user_biography'. Is that "strcasecmp" is usefull ??
Then just change 'user_name' for 'user_biography'. If it returns anything but 0 it means the value was changed.
@SabbirHossain Glad to help. If this is the answer to your question, then mark it as such for future reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.