我有一个自定义表,我正在通过wp\\u ajax操作更新它。插入一行并插入除id
这是一个AUTO_INCREMENT
. 我有一个ajax响应,它使用新数据在页面上创建新行。在我的响应中,我需要查看是否添加了行,然后获取要显示的记录。我当然可以打印除id
使用我预定义的变量,但我也想获得动态创建的数字!帮助我需要一个if
语句以查看行何时完成保存。
问题在于我的php,特别是$carrier_id
:
<?php
add_action(\'wp_ajax_change_carrier\', \'carrier_change_callback\');
function carrier_change_callback() {
global $wpdb;
//New Carrier
if ($_POST[\'newCarrier\']){
$wpdb->insert(
$wpdb->prefix.\'bf_carriers\',
array(
\'name\' => stripslashes($_POST[\'newName\']),
\'label\' => $_POST[\'newLabel\'],
\'service_center_path\' => $_POST[\'newHtm\'],
\'image_name\' => $_POST[\'newImage\']
)
);
//set the variables to return the new Table Row
$carrier_name = stripslashes($_POST[\'newName\']);
$carrier_image = $_POST[\'newImage\'];
$carrier_label = $_POST[\'newLabel\'];
$carrier_htm = $_POST[\'newHtm\'];
$carrier_id = $wpdb->get_row("SELECT id FROM $wpdb->prefix.\'bf_carriers\' WHERE image_name = $carrier_image");
?>
<tr>
<!-- Lots of junk going on in here to display above variables and return the response to my ajax call -->
</tr>
<?php
die();
}
}