- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在尝试获取提交表单的人的用户名,与他们提交的值一起存储在数据库中。
这是我的函数中的第 139 行:
$retval = $newdb->query("SELECT * FROM $table WHERE user = '$hf_username' ");
add_action("init", "ref_access");
function ref_access() {
global $error;
if ( is_user_logged_in() ) {
global $quanid;
global $newdb;
$hf_username = wp_get_current_user();
$inputValue = isset($_POST['$quanid']);
$newdb = new wpdb( 'user', 'password', 'db', 'localhost' );
$retval = $newdb->query("SELECT * FROM $table WHERE user = '$hf_username' ");
if( mysqli_num_rows($retval) > 0)
{
$newdb->query("UPDATE table SET user = '$hf_username' "); //If user exists, update
}
else
{
global $table;
global $newdb;
$newdb->insert(
$table,
array(
'ItemID' => $quanid,
'Price' => $inputValue,
'user' => $hf_username
)
);
}
} else {
$error = "Error: You must be logged in to submit prices";
return;
}
}
最佳答案
wp_get_current_user
返回一个 WP_User
对象,而不是字符串形式的用户名。用户名存储在 user_login
对象的 WP_User
属性中。
$hf_user = wp_get_current_user();
$hf_username = $hf_user->user_login;
mysqli_
函数混合在一起。 $newdb->query
将已经返回所选行的数量,无需调用 mysqli_num_rows
并且它不会以您期望的方式工作。 global $wpdb
使用现有的数据库对象。如果您访问安装了 WordPress 的同一个数据库,则不需要这样做。 关于wordpress - 可捕获的 fatal error : Object of class WP_User could not be converted to string in/directory/on line 139,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29189996/
我正在使用 XAMPP 在 Mac (OSx Sierra) 上本地开发一个 WordPress 主题。它被设置为当我在 URL 中键入 localhost/ThemeName 时,我被带到我的站点。
在表 WP_USER 中添加新列是否好 - 或者 - 我应该在 metauser 表中添加内容吗?我在质疑这个,因为有一个 WP 功能 /* Get full WP_User object insta
正在脱机处理一个站点,突然出现 mysql 端口冲突错误,然后我不得不花很多时间研究它的解决方案,但没有运气。所以我从 xampp 手动获取主题文件和数据库,并将它们粘贴到另一个安装了新 xampp
在表 WP_USER 中添加新列是否好 - 或者 - 我应该在 metauser 表中添加内容吗?我在质疑这个,因为有一个 WP 功能 /* Get full WP_User object insta
我需要自定义数据,这就是为什么我在应用插入查询时创建了一个名为 company_name 的列,然后插入了所有数据,但未插入 company_name 数据。 下面是我的代码示例: $userdata
SELECT * FROM `wp_users` group by date(user_registered),month(user_registered) 表中有 4 条记录,但查询仅返回每个日
当用户注册时,数据将进入标准 wp_users 表。但我创建了一个新表,我想将所有(新)注册用户存储在其中。我怎样才能改变它? 最佳答案 add_action('user_register', 'my
我有一个代码示例: function custom_func(){ global $wpdb; $wpdb->flush(); //tried with and without
我使用网站的仪表板在 Wordpress 上创建了一个新用户。新用户已成功创建,我可以使用创建的用户登录。然而,当我检查网站使用的 MySQL 数据库时,我惊讶地发现 wp_user 表中没有新条目反
我无法登录到管理仪表板。当我转到 localhost/nutri/wp-admin 时,它会自动将我重定向到: http://localhost/nutri/wp-login.php?redirect
我正在编写一个基本插件。这是我的代码: $new_user = get_userdata($user_id); //$user_id is passed as a parameter $fir
我创建了一个简单的 html 表单来向我编写的 php 脚本提交一个值。我正在使用WordPress。我希望脚本在 user_meta 表中查找用户,然后选择用户 ID。然后我希望脚本在 wp_use
有没有办法从单独的 WordPress 安装中检索 WP_User 对象? 我正在尝试显示另一个 Wordpress 站点的用户列表。我不一定希望新的 WordPress 网站共享相同的用户,我只需要
我创建了一个简单的 html 表单,用于向我编写的 php 脚本提交两个值(车牌号和状态)。我正在使用 wordpress。我希望脚本在 wp_usermeta 表中查找用户,并选择具有与表单中提交的
我正在编写一个插件,它使用...从 WordPress 数据库中获取一组数据 $data = $wpdb->get_results("SELECT * FROM $wpdb->users", ARRA
我有一个自定义查询,可以使用我编写的统计插件的 user_meta 拉取用户。我可以根据日期范围选择 (WHERE),也可以按任何元字段进行排序,但是,我不能同时进行这两项操作。我快疯了!!这是我的查
如果我这样做,我会显示许多属性,包括 display_name,但不会显示名字和姓氏 $user = get_userdata( 4 ); print_r( $user ); 但是它们显然存在,因为如
这就是我能够将每个用户记录的所有相关数据提取到一行中的方法: SELECT user_login, user_pass, user_email, user_registered, meta1.meta
默认情况下,wordpress 会清理写入 wp_users 表中的 user_nicename 列的内容。它将删除空格、一些特殊字符并将大写字母更改为小写字母。是否可以在不进行清理的情况下更新 us
我们正在使用 WordPress 来开发您的网站。当 user_status=2 时,用户处于事件状态;当 user_status=0 时,用户处于非事件状态。那么user_status=1是什么意思
我是一名优秀的程序员,十分优秀!