0

I am trying to insert multiple checkbox values in my database with the function insert() of WordPress, but it don't work same when I use a SQL request. Although my table exist I really don't see where is the problem...

    <form name="orderform" method="post" >  
    <table id="Tableau" style="border-collapse: collapse;" id="tableauS" border="1"><tr><th>Attributs</th><th>Choix</th></tr></html>
    <?php

    $resultat= $wpdb->get_results("SELECT * from wp_frm_fields ",ARRAY_N); // lancement de la requete

    foreach ($resultat as $post) {  
        echo '<tr><td>'.$post[2].'</td>';
        echo"<td><center><input type='checkbox' name='choixP' value='".$post[0]."'></center></td>";
    }
    ?>
    <html></tr>

       <input type="submit" name="sub" value="submit">

    </table></form>
    <?php

    if(isset($_POST['sub']))  
    {  
    global wpdb;
    $checkbox1=$_POST['choixP'];  
    $chk="";  
    foreach($checkbox1 as $chk1)  
       {  
          $chk = $chk1;  

         $wpdb->insert( 'wp_choix_attributs_liste',
         array('att_id'=>$chk), 
         array(%s) );

       -------- Dont Work too-----------    
          $query = "INSERT INTO wp_choix_attributs_liste (att_id)  VALUES ('".$chk."')";
          mysql_query($query) or die(mysql_error());
       ---------------------------------

       }  
    }

1 Answer 1

0

I solve it.

public function insertionRow($id){

    global $wpdb;
    $wpdb->query("INSERT INTO wp_choix_attributs_liste (att_id) VALUES (".$id.");");
}

In my html with the checkbox.

if(isset($_POST['sub']))  
    {  

        foreach ($_POST['choixP'] as $id) {
            self::insertionRow($id);
        }
    } 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.