WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WPDB scope issue? (3 posts)

  1. christopherharte
    Member
    Posted 5 years ago #

    Hello, and thank you for even taking a look! I am integrating a 'favorite post' system into the wordpress installation i am working on which allows users to choose their favorite videos to be posted to their profile. I have created a form buttun with hidden values which passes the users data as well as the id of the video to a form via POST in a separate php file. I have a little Javascript running on the page to prevent a refresh while the page is being viewed and just sends the info without causing any page disruption.

    I have tested the wpdb query i am trying to execute on a different page, and it seems to work fine. the problem arises in the query when the query is executed from a separate php page called through submission of the form.

    <?php 
    
    if(isset($_POST['favvid'])){
    
    $the_vid = ($_POST['favvid']);
    $user_id = ($_POST['userid']);
    $favs_array = ($_POST['favs']);
    
    $_favs_array = explode(",",$favs_array);
    $_favs_array[] = $the_vid;
    $new_favs = implode(",", $_favs_array);
    
    //------ Everything up to this point functions fine ------- //
    global $wpdb;
    $wpdb->query("UPDATE $wpdb->users SET favorite_vids = '$new_favs' WHERE $wpdb->users.ID = '$user_id' LIMIT 1");?>
    
    ?>

    The page which this from is on is located in the theme directory along with the rest of the theme files.

    Any ideas or suggestions as to where to start tackling this issue would be greatly appreciated :)

  2. christopherharte
    Member
    Posted 5 years ago #

    Whoops, under the code, i meant to say is that the code above is in getfav.php where the form submitting the POST to getfav.php is on a separate page also in the theme directory, thx!

  3. christopherharte
    Member
    Posted 5 years ago #

    Never mind, education is a funny and exciting thing, i figure ill just check out the wp-comments-post.php in the root and see whats going on there

Topic Closed

This topic has been closed to new replies.

About this Topic