Title: Can&#8217;t insert into my database
Last modified: June 8, 2023

---

# Can’t insert into my database

 *  [louma333](https://wordpress.org/support/users/louma333/)
 * (@louma333)
 * [3 years ago](https://wordpress.org/support/topic/cant-insert-into-my-database/)
 * Hello friends,
 * I did a form with html and js, and through a plugin i coded in php, i’d like 
   to insert the result of this form into my wordpress database. But i run into 
   multiples problems. One was that wordpress would told me he couldnt find one 
   column that actually existed, and now that i removed that column from my data
   just to see, wordpress tell me the insertion was sucessfull. However, my table
   is empty. Nothing is added into it.
 * This is my php code that is supposed to insert it
 *     ```wp-block-code
       // Créer un tableau vide pour stocker les réponses nettoyées
           $reponse = array();
   
           // Parcourir le tableau $_POST et nettoyer chaque valeur
           foreach ($_POST as $key => $value) {
               if (!empty($value)) {
                   $reponse[$key] = sanitize_text_field($value);
               }
           }
   
           // Insérer les données en utilisant $wpdb->insert
           $result = $wpdb->insert($table_name, $reponse);
   
   
       // Vérifier le résultat
       if ($result === false) {
         echo "Erreur lors de l'insertion des données : " . $wpdb->last_error;
       } else {
           echo "L'insertion des données a réussi";
       }
       print_r($wpdb->queries);
   
   
       $result = $wpdb->insert($table_name, $data);
   
       }
       ```
   
 * When i print_r my queries, i can see multiple submissions i did to the form. 
   I even don’t know how it is possible. I see 25 differents submissions that was
   done on differents days. How can it keep so much of the informations if there
   are not even kept anywhere in the database ? For example :
 *     ```wp-block-code
        [16] => stdClass Object
               (
                   [id] => 17
                   [Nom] => Test
                   [Prenom] => Test
                   [Adresse] => Test
                   [Code-Postale] => Test
                   [Naissance] => 2000-01-01
                   [Telephone] => Test
                   [Mail] => test@test.com
                   [Probleme-de-sante] => 
                   [handicap] => Test
                   [RQTH] => 
                   [Autre-aide] => 
               )
       ```
   
 * And when i try to insert something into my database through direct mysql in my
   phpmyadmin, it works ! So how is it possible ? It’s not a problem of the database
   since it work. But for some reason there is something preventing my data to be
   inserted.
   Ofc i already checked the code is connected to the right database and
   right table, i did an echo to check it.If you could help me, i would trully appreciate
   it.

Viewing 1 replies (of 1 total)

 *  Moderator [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * (@bcworkz)
 * [3 years ago](https://wordpress.org/support/topic/cant-insert-into-my-database/#post-16804625)
 * There are many places things can go awry between your form and the DB. The out
   of context snippet you provided is not enough information for anyone to speculate
   about what is going wrong. I suggest you post somewhere outside of these forums
   your form’s HTML, its JS, and the complete PHP which handles the form submission.
   Enough information that someone could test your code themselves if they were 
   so inclined. A couple possible places to post are pastebin.com and gist.github.
   com.
 * With access to complete information, hopefully someone will be able to spot where
   the problem is.

Viewing 1 replies (of 1 total)

The topic ‘Can’t insert into my database’ is closed to new replies.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [insertion](https://wordpress.org/support/topic-tag/insertion/)
 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [bcworkz](https://wordpress.org/support/users/bcworkz/)
 * Last activity: [3 years ago](https://wordpress.org/support/topic/cant-insert-into-my-database/#post-16804625)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
