Discussion:
getting user_id in buddypress profile page
BenderisGreat
2013-10-05 23:22:35 UTC
Permalink
This is likely very simple, but I am having an issue with it.

I am using

<?php
global $wpdb, $userdata, $current_user;
$current_user = wp_get_current_user();
$userid = $current_user->ID;
?>


I can echo out $userid and it shows the correct user ID, but when I put it
into the form submit;

$wpdb->insert(wp_jo_plugin_options, array (
'user_id' => $userid,
'length' => $_POST['length'],
'girth' => $_POST['girth'],
'date' => $_POST['date'],

it just posts a 0 to the database. Am I doing something wrong here? It
seems very straight forward, never had an issue with such a simple task.
But trying to add this code to buddypress is a real hassle.




--
View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/getting-user-id-in-buddypress-profile-page-tp42444.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
Eric Hendrix
2013-10-06 03:05:39 UTC
Permalink
Shouldn't you be using double quotes around your vars (associative array
syntax)?
Post by BenderisGreat
This is likely very simple, but I am having an issue with it.
I am using
<?php
global $wpdb, $userdata, $current_user;
$current_user = wp_get_current_user();
$userid = $current_user->ID;
?>
I can echo out $userid and it shows the correct user ID, but when I put it
into the form submit;
$wpdb->insert(wp_jo_plugin_options, array (
'user_id' => $userid,
'length' => $_POST['length'],
'girth' => $_POST['girth'],
'date' => $_POST['date'],
it just posts a 0 to the database. Am I doing something wrong here? It
seems very straight forward, never had an issue with such a simple task.
But trying to add this code to buddypress is a real hassle.
--
http://wordpress-hackers.1065353.n5.nabble.com/getting-user-id-in-buddypress-profile-page-tp42444.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
--
*Eric A. Hendrix*
***@gmail.com
(910) 644-8940

*"Non Timebo Mala"*
J.D. Grimes
2013-10-06 20:24:28 UTC
Permalink
I don't see anything wrong with that. Try changing it to

'user_id' => get_current_user_id(),

Are you sure that $userid is being set above your insert code?

-J.D.
Post by BenderisGreat
This is likely very simple, but I am having an issue with it.
I am using
<?php
global $wpdb, $userdata, $current_user;
$current_user = wp_get_current_user();
$userid = $current_user->ID;
?>
I can echo out $userid and it shows the correct user ID, but when I put it
into the form submit;
$wpdb->insert(wp_jo_plugin_options, array (
'user_id' => $userid,
'length' => $_POST['length'],
'girth' => $_POST['girth'],
'date' => $_POST['date'],
it just posts a 0 to the database. Am I doing something wrong here? It
seems very straight forward, never had an issue with such a simple task.
But trying to add this code to buddypress is a real hassle.
--
View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/getting-user-id-in-buddypress-profile-page-tp42444.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
mohammad aghanabi
2013-10-06 20:31:47 UTC
Permalink
Please vardump the $userid variable. also try to use bp_displayed_user_id()
for getting user id in a profile.
Post by J.D. Grimes
I don't see anything wrong with that. Try changing it to
'user_id' => get_current_user_id(),
Are you sure that $userid is being set above your insert code?
-J.D.
Post by BenderisGreat
This is likely very simple, but I am having an issue with it.
I am using
<?php
global $wpdb, $userdata, $current_user;
$current_user = wp_get_current_user();
$userid = $current_user->ID;
?>
I can echo out $userid and it shows the correct user ID, but when I put
it
Post by BenderisGreat
into the form submit;
$wpdb->insert(wp_jo_plugin_options, array (
'user_id' => $userid,
'length' => $_POST['length'],
'girth' => $_POST['girth'],
'date' => $_POST['date'],
it just posts a 0 to the database. Am I doing something wrong here? It
seems very straight forward, never had an issue with such a simple task.
But trying to add this code to buddypress is a real hassle.
--
http://wordpress-hackers.1065353.n5.nabble.com/getting-user-id-in-buddypress-profile-page-tp42444.html
Post by BenderisGreat
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Abdussamad Abdurrazzaq
2013-10-06 23:19:59 UTC
Permalink
In the below code the first argument has to be a string so you should
put the table name in quotes. Also use $wpdb->prefix to refer to the
table prefix instead of "wp_" because this is something that can be
changed when installing wordpress and varies in multi site installs.

$wpdb->insert(wp_jo_plugin_options, array (
'user_id' => $userid,
'length' => $_POST['length'],
'girth' => $_POST['girth'],
'date' => $_POST['date'],
)
);

If you want to use the global variable $current_user why call
wp_get_current_user again?

Finally there is this:

"Use the init or any subsequent action to call this function. Calling
it outside of an action can lead to troubles. See #14024 for details. "

http://codex.wordpress.org/Function_Reference/wp_get_current_user
Post by BenderisGreat
This is likely very simple, but I am having an issue with it.
I am using
<?php
global $wpdb, $userdata, $current_user;
$current_user = wp_get_current_user();
$userid = $current_user->ID;
?>
I can echo out $userid and it shows the correct user ID, but when I put it
into the form submit;
$wpdb->insert(wp_jo_plugin_options, array (
'user_id' => $userid,
'length' => $_POST['length'],
'girth' => $_POST['girth'],
'date' => $_POST['date'],
it just posts a 0 to the database. Am I doing something wrong here? It
seems very straight forward, never had an issue with such a simple task.
But trying to add this code to buddypress is a real hassle.
--
View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/getting-user-id-in-buddypress-profile-page-tp42444.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Loading...