我试图通过创建一个表将数据插入wordpress数据库.我创建了表,但是当我尝试从表单插入数据时,它不会插入数据.我已检查数据库连接是否正常,但插入不会发生.有人可以帮我吗?这是我的代码: –
PHP
require_once('/wp-config.php');
global $wpdb;
if(isset($_POST['submit'])){
$wpdb->insert( 'wp_post_job',array( 'organizationname' =>
$_POST['organizationname'],'post' => $_POST['post'],'publishfrom' =>
$_POST['publishfrom'],'publishupto' => $_POST['publishupto'],'qualification1' => $_POST['qualification1'],'qualification2' =>
$_POST['qualification2'],'qualification3' => $_POST['qualification3'],'qualification4' => $_POST['qualification4'],'experience1' =>
$_POST['experience1'],'experience2' => $_POST['experience2'],'experience3' => $_POST['experience3'],'training1' => $_POST['training1'],'training2' => $_POST['training2'],'training3' => $_POST['training3'],'training4' => $_POST['training4'],'training5' => $_POST['training5'] ),array( '$s','$s','$s' ) );
}
?>
PHP
/*
Template Name: Form
*/
?>
PHP global $pc_theme_object; /* Reference theme framework class */ ?>
PHP get_header(); ?>
最佳答案
将’$s’替换为’%s’
使用此代码
if ( isset( $_POST['submit'] ) ){
global $wpdb;
$tablename = $wpdb->prefix.'post_job';
$wpdb->insert( $tablename,array(
'organizationname' => $_POST['organizationname'],'publishfrom' => $_POST['publishfrom'],'qualification2' => $_POST['qualification2'],'experience1' => $_POST['experience1'],array( '%s','%s','%s' )
);
}