• Resolved hkapadia

    (@hkapadia)


    Hi Michael,

    Thanks for this plugin. It’s great. I went ahead and bought the editor plug-in too but I have one question.

    I am trying to programatically (using php) update the value in a certain column in the db for an existing record. While the editor allows me to do it using the UI, I would like to do it using a function when someone presses a certain button on a screen.

    I found this https://cfdbplugin.com/?page_id=377. This partially works as it creates a separate record for each new $data object. How do I get it to update an existing record?

    Thanks,
    Hunain

    https://www.ads-software.com/plugins/contact-form-7-to-database-extension/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    You would have to attach an AJAX call to the button and do a POST to the admin URL admin-ajax.php?action=cfdb-edit
    In that request:
    1. set “value” = the new value
    2. set “key” = “submit_time,field_name” (replacing for the actual values)

    Thread Starter hkapadia

    (@hkapadia)

    Hey Michael,

    That doesn’t seem to be working out well for me. My code looks like this

    $url = 'https://beta.developpakistan.org/wp-admin/admin-ajax.php?action=cfdb-edit';
              $fields = array(
             			"value" => '9902',
             			"key" => '1439180125.5002, vs_amount-collected'
    			);
    
    //url-ify the data for the POST
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    rtrim($fields_string, '&');
    
    //open connection
    $ch = curl_init();
    
    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL, $url);
    curl_setopt($ch,CURLOPT_POST, count($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);

    Is there any syntax error I am making?

    Thanks,
    Hunain

    Plugin Author Michael Simpson

    (@msimpson)

    No space in the key after the comma. You will also need to be logged into WordPress to access that URL.

    Thread Starter hkapadia

    (@hkapadia)

    Thanks Michael!

    The being logged in thing is a bummer :(. It would be great to be able to change values in the db based on actions performed by any user on the website.

    Anyways I got it to work by just using wpdb->query(“update query”).

    Thanks for this plugin though. It is fantastic!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Updating values in CFDB using php’ is closed to new replies.