我试图将数据插入到名为 Ships 的表中,但遗憾的是它不起作用。我粘贴了代码,以便您更好地了解我是如何编写脚本的。任何帮助深表感谢!
<?php
require_once('../../../wp-config.php');
global $wpdb;
?>
<?php
$json_data = $_POST['info'];
if( isset($json_data) ){
$eniNumber = $json_data['EniNumber'];
$name = $json_data['Name'];
$startDate = $json_data['StartDate'];
$rows = $json_data['Rows'];
$table_name = $wpdb->prefix . "Ships";
$result = $wpdb->insert( $table_name, array(
'eniNumber' => $eniNumber,
'name' => $name,
'startDate' => $startDate
) );
if( $result ){
echo json_encode("Entered data successfully");
}else{
echo json_encode("Insertion failed");
}
} else {
echo json_encode( "What happened?" );
}
?>