Skip to content
Advertisement

WordPress save data to DB via AJAX

I’m quite new to WordpPress and web development as in general. Trying to save data to wordpress DB from the form I have on the page via ajax call.

This is the form I have:

JavaScript

This is an AJAX. It is wrapped into jQuery function, so it works for sure:

JavaScript

Finally this is a code I have in my functions.php

JavaScript

Looks like code is working as data get passed to the server, but it is not getting saved to the DB. Would appreciate if somebody can tell what I’m doing wrong. Thank you.

Advertisement

Answer

There are a few issues I can see, namely, you are not passing in the correct variable to the $_POST. You also need to specify the name of the database table. Try the following code for database inserting.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement