When I make a modification to data that is read into a form using MYSQL, I want to apply those changes to the database. But even when successfully submitting a form, the $_POST values are not changing, they remain with the old values.
I am seeing the changed value in AJAX, and I even try an insert into the database with the values in AJAX, but that is not working...
I have spent days on this, can anyone help? If I could get if(isset($_POST['FirstName'])) to fire off, then I would be good, but I can't seem to get this to happen. I will attach portions of my code, there is a lot, but I will attach the ones that are applicable.

// SNIPPETS FROM THE FORM:  This is contained in php_DOC.php
<form id="PhysicianForm" method="POST" enctype="multipart/form-data"
                autocomplete="off" action="<?php echo admin_url('admin-ajax.php'); ?>" >      
 <input type="hidden" name="action" value="CreateProfile">

// This prints out the modified FirstName value correctly, this is the only place I can get the modified value.  This is contained in php_DOC.php
    jQuery('#SubmitInsHrs').click( function () {
        var FirstName = jQuery('#FirstName').val();
            alert('FirstName being updated...', FirstName);

            url: 'admin-ajax.php',
            type: "POST",
            data: {
                'action': 'post_language',
                'FirstNM': FirstName,

            success: function (data) {


These are in functions.php


function CreateProfile(){
  wp_send_json_success( $_POST );

function enqueue_jqery_form (){

I also tried this, to just force insert with new value, but no insert happens….

function post_language(){

    global $wpdb;
    alert('post_language is called');

    $FirstName = isset( $_POST['FirstName'] ) ? $_POST['FirstName'] : '';

    $table = 'Provider';

    $wpdb->insert( $table, array('FirstNM' => $FirstName));
add_action('wp_ajax_post_language', 'post_language');
  • Have you considered using the REST API endpoints for your AJAX requests instead? They're much easier to use and debug, if Admin AJAX fails it just gives you a cryptic message. REST API endpoints tell you in plain english why it failed. Also, your code doesn't sanitise or validate values, which can be a security problem, it just assumes the firstname is a first name, and not something else – Tom J Nowell Apr 30 '19 at 18:53
  • Who can send this form? If the form is sent by a logged-in user, it's OK. But if it can be sent without logging into the WordPress, the proper action hook will be wp_ajax_nopriv_{action-name}, in this case wp_ajax_nopriv_CreateProfile. – nmr May 2 '19 at 20:40

Add this to functions.php


and then make either of following changes in your code.

Because your jquery code is sending FirstNM to server (not FirstName). Therefore in post_language() function, change this line

$FirstName = isset( $_POST['FirstName'] ) ? $_POST['FirstName'] : '';


    $FirstName = isset( $_POST['FirstNM'] ) ? $_POST['FirstNM'] : '';

Change 'FirstNM': FirstName, to 'FirstName': FirstName, in ajax call.

data: {
            'action': 'post_language',
            'FirstName': FirstName,     // 'FirstNM': FirstName,

Also remove this line,from post_language() function if yo have not defined alert() in your PHP It seems to be a JS function added to PHP by mistake, resulting in a PHP error.

    alert('post_language is called');
| improve this answer | |
  • 1
    I think FirstNm => FirstName is indeed the issue here. – phatskat May 1 '19 at 19:25
  • Well, I changed all occurrences of FirstName to FirstNM, so that all are the same. FirstNM is the column name in my database. FirstName is the form name. But this did not fix the issue. Thanks, – Monica May 2 '19 at 14:02
  • Did you added add_action('wp_ajax_post_language','post_language'); to functions.php? – Qaisar Feroz May 2 '19 at 16:25
  • @phatskat you are right. – Qaisar Feroz May 2 '19 at 16:26
  • @Monica see the updated answer. – Qaisar Feroz May 2 '19 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.