我正在尝试将数据插入使用$ wpdb创建的sql表中
我尝试了很多事情,但是没有一件对我有用。 有任何想法吗? (我有一个具有自动递增功能的id列)
<?php /* Template Name: My Custom Page */
require_once("header.php");
?>
<div class="wrap">
<form action="" method="post">
FFFirstName <input type="text" name="nametxt" value="" /><br/>
<input name="Submit" type="submit" value="Submit">
</form>
<?php
if( isset($_POST['submit']) )
{
global $wpdb;
$firstName = $_POST["nametxt"];
echo $firstName;
$table = $wpdb->prefix."invoice";
$wpdb->insert($table,array('name' => $firstName ));
}
$wpdb->print_error();
$wpdb->show_errors();
?>
</div>
答案 0 :(得分:1)
尝试一下
ALTER TABLE wp_invoice修改列ID INT(5)自动递增
<?php
/*
Template Name: My Custom Page
*/
if( isset($_POST['submit']) )
{
global $wpdb;
$firstName = $_POST["nametxt"];
echo $firstName;
$table = $wpdb->prefix."invoice";
$wpdb->insert($table,array('name' => $firstName ));
}
$wpdb->print_error();
$wpdb->show_errors();
?>
<?php require_once("header.php");?>
<div class="wrap">
<form action="" method="post">
FFFirstName <input type="text" name="nametxt" value="" /><br/>
<input name="submit" type="submit" value="Submit">
</form>
</div>
答案 1 :(得分:0)
表结构
table `wp_invoice`
--
CREATE TABLE `wp_invoice` (
`ID` int(5) NOT NULL,
`name` varchar(20) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `wp_invoice`
--
INSERT INTO `wp_invoice` (`ID`, `name`) VALUES
(2, 'shasy'),
(0, 'shay');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `wp_invoice`
--
ALTER TABLE `wp_invoice`
ADD PRIMARY KEY (`ID`) USING BTREE;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
答案 2 :(得分:-1)
全局$ firstName = $ _POST [“ nametxt”];