我试图通过创建一个“wp\u ecoles\u details”表将数据插入wordpress数据库。我已经创建了表,但是当我尝试从窗体插入数据时,它不会插入数据。我已经检查了数据库连接是否正常,但是插入没有发生。有人能帮我吗?这是我的code:-
<?php
/**
* Template Name: cours_page
*
* Creates a page with posts, akin to the default index.php. Using this template you can create as many pages of posts as you want.
*
* @package thim
*/
get_header();
if ( is_user_logged_in() ) {
global $wpdb;
global $current_user;
$user = wp_get_current_user();
//echo ($user);
$post_id = $wpdb->get_results("SELECT DISTINCT user_id FROM $wpdb->pmpro_membership_orders");
if ( isset( $_POST['submit'] ) ){
$type = $_POST["type"];
$nom_ecole = $_POST["nom_ecole"];
$adresse = $_POST["adresse"];
$postale = $_POST["postale"];
$ville = $_POST["ville"];
$telephone = $_POST["telephone"];
$classes = $_POST["classes"];
$total_eleve = $_POST["total_eleve"];
$n_scolaire = $_POST["n_scolaire"];
global $wpdb;
$wpdb->insert('wp_ecoles_details', array(
'type' => $type ,
'nom_ecole' => $nom_ecole,
'adresse' => $adresse,
'postale' => $postale,
'ville' => $ville,
'telephone' => $telephone,
'classes' => $classes,
'total_eleve' => $total_eleve,
'n_scolaire' => $n_scolaire
),
array( '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s' ));
}
?>
<div class="ecole_div" id="ecole_div">
<form method="post">
<fieldset>
<legend>Information sur l’école:</legend>
<input type="radio" name="type" value="privee"> Privée
<input type="radio" name="type" value="publique"> Publique
<br> <br>
Nom de l’école:<br>
<input type="text" name="nom_ecole" value="">
<br>
Adresse:<br>
<textarea rows="4" cols="50" name="adresse" value="">
</textarea>
<br>
Code postal:<br>
<input type="number" name="postal" value="">
<br>
Ville:<br>
<input type="text" name="ville" value="">
<br><br>
Téléphone école:<br>
<input type="text" name="telephone" value="">
<br>
Nombre de classes:<br>
<input type="number" name="classes" value="">
<br><br>
Nombre total d’élèves:<br>
<input type="number" name="total_eleve" value="">
<br>
Niveau scolaire
<input type="checkbox" name="n_scolaire" value="maternelle"> Maternelle
<input type="checkbox" name="n_scolaire" value="primaire"> Primaire
<input type="checkbox" name="n_scolaire" value="elementaire"> Elémentaire
<br><br>
<input type="submit" value="Submit">
</fieldset>
</form>
</div>
1条答案
按热度按时间rseugnpd1#
您有一个名为
postal
在您的表单中,但在您的代码中,您试图从中获得价值postale
.代替
与th
更新:
将name属性添加到submit按钮: