Title: WPDB scope issue?
Last modified: August 19, 2016

---

# WPDB scope issue?

 *  Resolved [christopherharte](https://wordpress.org/support/users/christopherharte/)
 * (@christopherharte)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/wpdb-scope-issue/)
 * 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 🙂

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

 *  Thread Starter [christopherharte](https://wordpress.org/support/users/christopherharte/)
 * (@christopherharte)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/wpdb-scope-issue/#post-1038379)
 * 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!
 *  Thread Starter [christopherharte](https://wordpress.org/support/users/christopherharte/)
 * (@christopherharte)
 * [17 years, 2 months ago](https://wordpress.org/support/topic/wpdb-scope-issue/#post-1038384)
 * 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

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

The topic ‘WPDB scope issue?’ is closed to new replies.

## Tags

 * [$_POST](https://wordpress.org/support/topic-tag/_post/)
 * [execute](https://wordpress.org/support/topic-tag/execute/)
 * [fail](https://wordpress.org/support/topic-tag/fail/)
 * [form](https://wordpress.org/support/topic-tag/form/)
 * [problem](https://wordpress.org/support/topic-tag/problem/)
 * [wpdb](https://wordpress.org/support/topic-tag/wpdb/)
 * [wp_query](https://wordpress.org/support/topic-tag/wp_query/)

 * 2 replies
 * 1 participant
 * Last reply from: [christopherharte](https://wordpress.org/support/users/christopherharte/)
 * Last activity: [17 years, 2 months ago](https://wordpress.org/support/topic/wpdb-scope-issue/#post-1038384)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
