以下是您认为开箱即用的脚本。
function ajax_away_dates() {
global $wpdb; // this is how you get access to the database
$bookonline = $wpdb->prefix . "book_online";
$dateedit = $_POST['data'];
$date=date("Y-m-d",strtotime($dateedit));
$wpdb->insert(
$bookonline,
array(
'allday' => 1,
'appiontmentdate' => $date
),
array(
'%s',
'%d'
)
);
// $wpdb->query("INSERT INTO $bookonline ('allDay','appiontmentdate') SET ('1','$dateedit')");
print $wpdb->last_query;
return $wpdb->print_error(); /*$whatever += 10;
echo $whatever;
*/
wp_die(); // this is required to terminate immediately and return a proper response
}
我也试过
$date=date('Y-m-d',strtotime($dateedit));
$query = array(
'allDay' => 1,
'appiontmentdate' => $date
);
$wpdb->insert(
$bookonline,
$query);
和jQuery
function senttocalserver(d){
jQuery.post(
ajaxurl,
{
'action': 'calendaradd',
'data': d
},
function(response){
alert('The server responded: ' + response);
}
);
}
网址编码如
action=calendaradd&data=2015-12-7
但是会发生什么呢,它会在2015年之后停止,见下文
The server responded: INSERT INTO `zo_book_online` (`allday`, `appiontmentdate`) VALUES ('1', 2015)0
答案 0 :(得分:0)
$wpdb->insert(
$bookonline,
array(
'allday' => 1,
'appiontmentdate' => $date
),
array(
'%s',
'%d'
)
);
此处' %d
'表示您正在插入整数remove array( '%s', '%d' )
,它是可选部分,应该可以使用。
那将是
$wpdb->insert(
$bookonline,
array(
'allday' => 1,
'appiontmentdate' => $date
)
);