我试图将新表格行插入自定义wpdb表格。数据来自发布到脚本的表单。
我在脚本开头声明全局$ wpdb并插入数据库,但由于某种原因它不喜欢查询功能,WordPress建议在codex中使用。 我收到此错误致命错误:调用成员函数查询()
这是我的代码:
<?php
global $wpdb;
if($_POST){
$post_id = $_POST['post_id'];
$name = $_POST['name'];
$email = $_POST['email'];
$city = $_POST['city'];
$tell = $_POST['tell'];
$date_m = $_POST['date_m'];
$date_y = $_POST['date_y'];
$consent = $_POST['consent'];
$check_error = 0;
if (!isset($name) || $name == ''){
echo "empty";
$check_error = 1;
}
elseif (!isset($email) || $email == ''){
echo "empty";
$check_error = 1;
}
$name = mysql_real_escape_string($name);
$email = mysql_real_escape_string($email);
$city = mysql_real_escape_string($city);
$tell = mysql_real_escape_string($tell);
$date_m = mysql_real_escape_string($date_m);
$date_y = mysql_real_escape_string($date_y);
$consent = mysql_real_escape_string($consent);
$query = "INSERT INTO {$wpdb->prefix}kishvote SET ";
$query .= "post_id = '" . $post_id . "', ";
$query .= "date_timevote = '" . date( 'Y-m-d H:i:s' ) . "', ";
$query .= "u_name = '" . $name . "', ";
$query .= "u_city = '" . $city . "', ";
$query .= "u_mail = '" . $email . "', ";
$query .= "u_tell = '" . $tell . "', ";
$query .= "date_m = '" . $date_m . "', ";
$query .= "date_y = '" . $date_y . "', ";
$query .= "consent = '" . $consent . "', ";
$success = $wpdb->query( $query );
if ($success) {
$error = 0;
echo "submit";
} else {
$error = 1;
echo 'eror dade';
}
}
?>