Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] database update to bp_xprofile_data


  • yadigit
    Participant

    @yadigit

    I am trying to make a textarea form that will update user’s “bio” with out having to go to the profile tab.

    After looking in the mysql database and checking the structure of the table I noticed this..
    user_id = the profile id of the user..
    field_id = 5..
    (5 being the Bio form..)
    value = the string..

    Here is my code.

            echo '<form action="" method="post">
            <textarea rows="5" cols="26" name="bio_edit_form">';
            bp_member_profile_data( "field=Bio" );
            echo '</textarea>
            <input type="submit" name="submit" value="save"></form>';
            if(isset( $_POST["bio_edit_form"]) && strlen ( $_POST["bio_edit_form"] )){
                $wpdb->update(
                    'wp_bp_xprofile_data',
                    array(
                        'value' => 'rawr',
                        ),
                    array(
                        'user_id' => '1',
                        'field_id' => '5',
                        ),
                    array(
                        '%d',
                        '%d',
                        ),
                    array(
                        '%s',
                        )
                    );
            }

    Yes, I already globalized $wpdb AND $bp… I’ve checked this code with other working $wpdb->update codes that i’ve created and that works correctly.

    Can someone please tell me what I’m doing wrong here or why it’s not updating?

    Thanks in advance!

Viewing 5 replies - 1 through 5 (of 5 total)

  • shanebp
    Moderator

    @shanebp

    Why do you need the $bp global?

    Use the function meant for setting profile field data, and then you don’t need the $wpdb global either.
    http://stackoverflow.com/questions/12312372/how-to-update-custom-profile-field-data-in-buddypress


    yadigit
    Participant

    @yadigit

    Thank you for you’re answer. I’ve tried both methods and still haven’t gotten any results.

    here is my fill code.

    Note: loguser($loguser) == $bp->loggedin_user->id; (I made it into a function)..

    function bio_profile_field(){
        global $wpdb;
        $loguser = loguser($loguser);
        echo '<div id="primary" class="widget-area" role="complementary">';
            echo '<ul class="xoxo">';
                echo '<h3>Bio</h3>';
            echo '<hr />';
                if(empty($_POST["edit_bio"])){
                    bp_member_profile_data( 'field=Bio' );
                    echo '<hr />';
                    echo '<form action="" method="post">
                    <input type="hidden" name="edit_bio" value="1">
                    <input type="submit" name="likesubmit" value="edit"></form>';
                echo '</ul>';
            echo '</div>';
            if(isset( $_POST["edit_bio"]) && strlen( $_POST["edit_bio"])){bio_profile_field();}
        } else {
            echo '<form action="" method="post">
            <input type="hidden" name="edit_this_profile" value="1">
            <textarea rows="5" cols="26" name="bio_edit_form">';
            
            echo '</textarea>
            <input type="submit" name="submit" value="save"></form>';
            if(isset( $_POST["bio_edit_form"]) && strlen ( $_POST["bio_edit_form"] )){
                $field = '5';
                $value = $_POST["bio_edit_form"];
                $user_id = $loguser;
                $key = 'Bio';
                update_user_meta($user_id, $key, $value);
            }
        }
    }

    yadigit
    Participant

    @yadigit

    I’ve tried both methods.. still nothing. I don’t understand! I even used $wpdb->update. I still didn’t get any results.


    shanebp
    Moderator

    @shanebp

    No offense, but there are too many basic mistakes in your code to enumerate them.

    Untested, but try:

    function bio_profile_field(){
        $user_id = bp_loggedin_user_id();
        $bio = xprofile_get_field_data( 5, $user_id, 'comma' ); 
        ?>
        
       <div id="primary" class="widget-area" role="complementary">
    
            <h3>Bio</h3>
            <hr />
            <form action="" method="post">
            
                <input type="hidden" name="edit_bio" value="1">
                
                <textarea rows="5" cols="26" name="edit_bio_text">
                    <?php echo $bio; ?>
                </textarea>
                
                <input type="submit" name="likesubmit" value="SAVE">
            </form>    
        </div>
        
    <?php
    }
    
    function yadigit_save_bio() {
    
    	if( isset( $_POST["edit_bio"]) && $_POST["edit_bio"] == '1' ) ){
    	
    		$user_id = bp_loggedin_user_id();
    		
    		$value = sanitize_text_field( $_POST["edit_bio_text"] );
    		
    		$field = 5;
    		
    		xprofile_set_field_data( $field, $user_id, $value, false );
    	        
    	}
    }
    add_action( 'wp', 'yadigit_save_bio' );

    yadigit
    Participant

    @yadigit

    awesome!
    //Solved!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] database update to bp_xprofile_data’ is closed to new replies.
Skip to toolbar