我在wordpress数据库wp_applicants
中创建了一个带有表单和新表的自定义页面。当我提交时,它返回结果回显消息但不插入我的数据库表。请帮助。
代码:
<?php
/**
*Template Name: Career Temp
*/
get_header();
?>
<div class="page-header-wrap">
<header class="page-header">
<h1 class="page-header-title"><?php the_title(); ?></h1>
</header>
</div>
<div id="primary" class="content-area span_16 col clr clr-margin">
<div id="content" class="site-content" role="main">
<!-- paul removed post loop -->
<?php
if(isset($_POST['submit'])) {
global $wpdb;
$fname=$_POST['txt_fname'];
$lname=$_POST['txt_lname'];
$tbl="wp_applicants";
$others= $_POST['txt_email'];
$wpdb->insert('wp_applicants', array('first_name' => $fname, 'last_name' => $lname, 'email' => $others), array('%s', '%s', '%s'));
$msg = "Data Submited";
echo $msg;
}
?>
<form action="" method="post">
first name - <input type="text" name="txt_fname"/>
last name - <input type="text" name="txt_lname"/>
email - <input type="text" name="txt_email"/>
<input type="submit" name="submit"/>
</form>
</div><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
答案 0 :(得分:1)
尝试显示错误,如the Codex中所述。类似的东西:
$wpdb->show_errors();
$wpdb->insert('wp_applicants', array('first_name' => $fname, 'last_name' => $lname, 'email' => $others), array('%s', '%s', '%s'));
$wpdb->print_error();
$wpdb->hide_errors();