[英]wordpress: adding data to a custom table using $wpdb
I would like to add a form data to a custom table with the following: 我想使用以下内容将表单数据添加到自定义表:
Table name: wp_auctions
表名称:wp_auctions
Table fields : first_name, last_name
表格栏位:first_name,last_name
The file registration_form.php
is the registration form. 文件
registration_form.php
是注册表单。 The file registration.php
is the file that is intended to add data to the database table called wp_auctions
. 文件
registration.php
是用于将数据添加到名为wp_auctions
的数据库表中的wp_auctions
。
The problem is that data is not being added to the table after the form is submitted. 问题是提交表单后没有将数据添加到表中。 Any help?
有什么帮助吗? what am I doing wrong?
我究竟做错了什么?
It looks like $wpdb->insert()
is failing to run. 看来
$wpdb->insert()
无法运行。
Below are my two files: 以下是我的两个文件:
File: Registration_form.php 文件:Registration_form.php
<?php
/*
template name: Registration_form;
Author: Aboubacar DRAME
*/
?>
<?php
$directory=get_stylesheet_directory_uri();
?>
<form method= "POST", action=<?php echo $directory. "/registration.php"; ?>>
<label for="first_name"> First Name </label>
<input type="text" id="first_name" name="first_name"/> </br>
<input type="submit" name="submit" value="submit the form" />
</form>
File: registration.php 文件:registration.php
<?php
function Insert_data(){
global $wpdb;
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$wpdb->insert('wp_auctions',
array('first_name' => $first_name),
'last_name' => $last_name),
array('first_name' => '%s',
'last_name' => '%s')
);
}
if(isset($_POST['submit']))
{
Insert_data();
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.