$wpdb->insert ā Not working
-
Hello friends,
I did a form 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 a problem cause nothing is inserted in my database despite the log not pointing any error. My log tell me the insertion was sucessfull. However, my table is empty.
This is my php code that is supposed to insert it
echo "<pre>"; echo "Table name is :" . $table_name; echo "</pre>"; // Create an array with the reply $reply= array(); // Liste des champs que vous voulez insƩrer $champs = ['FirstName', 'LastName', 'Adress']; foreach ($champs as $champ) { if (!empty($_POST[$champ])) { $reply[$champ] = sanitize_text_field($_POST[$champ]); } } $result = $wpdb->insert($table_name, $reply); if ($result === false) { echo "Error : " . $wpdb->last_error; } else { echo "Data insertion was sucessfull"; } echo "<pre>"; print_r($wpdb->last_query); echo "</pre>"; echo "<pre>"; echo $wpdb->last_error; echo "</pre>"; } }
So what i get as result of all thoses echos is :
The correct name of my table which is : wp_inscriptions_majeurs
Then :
Data insertion was sucessfull
Then nothing for print_r($wpdb->last_query) :
INSERT INTO
wp_inscriptions_majeurs
(FirstName
,LastName
,Adress
) VALUES ('Test', 'Test', '21 Boulevard de Larramet')My echo $wpdb->last_error return an empty bloc. There is literally no error.
Can someone help me on this ?
Viewing 13 replies - 1 through 13 (of 13 total)
Viewing 13 replies - 1 through 13 (of 13 total)
- The topic ‘$wpdb->insert ā Not working’ is closed to new replies.