0

我正在尝试从多项选择中检索数据并使用 PHP。以下是创建选择列表并使用 MySQL 数据库中的信息填充它的代码:

    <select title="Basic example" multiple="multiple" name="id_categorie[]" size="3">
<?php
include_once('../../modeles/class_Categorie.php');
include_once '../../core/connx.php';
    foreach(Categorie::getAllCategorie()as $cat ){
    $categorie= new Categorie($cat->ID_CAT);
    echo '<option value="'.$categorie->getIDCategorie().'">'.$categorie->getNomCategorie().'</option>';
}
?>
</select> 

表单将使用方法的值发送到我尝试使用该语句POST的 URL :addArticle.phpimplode()

        include_once '../core/connx.php';
include_once('../modeles/class_Article.php');
include_once('../modeles/class_Image.php');
include_once '../modeles/class.upload.php';
$id=Article::creatArticle(0,$_POST['title'],implode(', ', $_POST['id_categorie']),$_POST['article']);
insertionImage($id,'img1');
function insertionImage($id,$img){
                $obj_img = new upload('../views/img/file/', $img);

                $obj_img->cl_taille_maxi = 1048579900000;
                $obj_img->cl_extensions = array('.gif','.jpg','.png','.jpeg'); // on attribut les extensions autorisées 
                $obj_img->cl_nb_char_aleatoire = 15;
                if (!$obj_img->uploadFichier('aleatoire')){
                      $erreur=$obj_img->affichageErreur();

                }
                else {
                    $chemin=$obj_img->cGetNameFileFinal();
                    Image::addImage($id,$chemin);

                }
}

以及添加文章类的功能Article

/**
 * function créeArticle
 */
public static function creatArticle($id_article,$title,$id_categorie,$article)
{
    global $db;

    $req = $db->prepare("INSERT INTO blog (ID_BLOG,TITLE,ID_CAT, ARTICLE,DATE) VALUES ('',:title,:id_categorie,:article,'".date('Y-m-d')."')");
    $ok = $req->execute(Array('title' =>$title,'id_categorie' => $id_categorie,'article' => $article));
     return $db->lastInsertId();
    //$erreur = $req->errorInfo();
}

问题是当我选择多个值时,我只能从表单中获得第一个选择的选项。如何获取所有选定的值?

4

0 回答 0