Note that there are some explanatory texts on larger screens.

plurals
  1. POinsert with Multi Select multiple values in single attribute
    primarykey
    data
    text
    <p>I am trying to retrieve data from a multiple select and using PHP. Here is the code creating the select list and populating it with information from a MySQL database:</p> <pre><code> &lt;select title="Basic example" multiple="multiple" name="id_categorie[]" size="3"&gt; &lt;?php include_once('../../modeles/class_Categorie.php'); include_once '../../core/connx.php'; foreach(Categorie::getAllCategorie()as $cat ){ $categorie= new Categorie($cat-&gt;ID_CAT); echo '&lt;option value="'.$categorie-&gt;getIDCategorie().'"&gt;'.$categorie-&gt;getNomCategorie().'&lt;/option&gt;'; } ?&gt; &lt;/select&gt; </code></pre> <p>The form sends the value using <code>POST</code> method to the URL <code>addArticle.php</code> where I try to use the <code>implode()</code> statement:</p> <pre><code> 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-&gt;cl_taille_maxi = 1048579900000; $obj_img-&gt;cl_extensions = array('.gif','.jpg','.png','.jpeg'); // on attribut les extensions autorisées $obj_img-&gt;cl_nb_char_aleatoire = 15; if (!$obj_img-&gt;uploadFichier('aleatoire')){ $erreur=$obj_img-&gt;affichageErreur(); } else { $chemin=$obj_img-&gt;cGetNameFileFinal(); Image::addImage($id,$chemin); } } </code></pre> <p>And the function that adds the article class <code>Article</code>:</p> <pre><code>/** * function créeArticle */ public static function creatArticle($id_article,$title,$id_categorie,$article) { global $db; $req = $db-&gt;prepare("INSERT INTO blog (ID_BLOG,TITLE,ID_CAT, ARTICLE,DATE) VALUES ('',:title,:id_categorie,:article,'".date('Y-m-d')."')"); $ok = $req-&gt;execute(Array('title' =&gt;$title,'id_categorie' =&gt; $id_categorie,'article' =&gt; $article)); return $db-&gt;lastInsertId(); //$erreur = $req-&gt;errorInfo(); } </code></pre> <p>The problem is when I select multiple values, I only get the first selected option from the form. How can I get all selected values?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload