我已经编写了一个代码,它将在提交时将表单数据保存在数据库中......
if(isset($_POST['submitted']) && ($_SERVER['REQUEST_METHOD'] == 'POST')) {
global $wpdb;
$company_name = $wpdb->prefix . "company";
$single_table = $wpdb->prefix . "single";
$emp_table = $wpdb->prefix . "employee";
$idea_table = $wpdb->prefix . "idea";
if($_POST['team-type'] == "Freelancer"){
$wpdb->query( $wpdb->prepare("INSERT INTO $company_name (name, team_size) VALUES(%s, %d)", $_POST['cname'],1));
$company_id = $wpdb->get_var( "SELECT MAX(id) FROM wp_company" );
echo "<h2>1</h2>";
$wpdb->query( $wpdb->prepare("INSERT INTO $single_table (company_id, name, bio,linkedin_url) VALUES (%d, %s, %s, %s)", $company_id, $_POST['freelancer-name'] ,$_POST['free-bio'], $_POST['free-url'] ) );
}else{
$query = "INSERT INTO $table_name (name, team_size) VALUES('" . $_POST['cname'] . "'," . $_POST['team'] .")";
$wpdb->query($query);
echo "<h2>2</h2>";
}
echo "<h2>3</h2>";
}
问题是,在数据库中,数据被存储了两次。
但是我放在页面上的 h2 标签只显示一次。
代码有什么问题,或者我应该怎么做才能只保存一次数据?
顺便说一句,如果条件也可以正常工作,bcz我可以根据我选择的内容检查h2标签吗?