How to Update Data in WordPress Database Using PHP with MySQL?

I want to send a RTR to our candidate, so I have made a form using Contact Form 7 plugin to fill up the form by myself & when I filled the form, an email will send to candidate with two buttons approved and declined. I created a form like: <label> Candidate Name [text* CandidateName autocomplete:name] </label> <label> Candidate Email [email* your-email autocomplete:email] </label> <label> Position [text* Position] </label> <label> Company [text* Company] </label> [hidden clientResponse "not received"] [submit "Submit"] Initially, the client response was set to "not received" when the client click on the "approved" or "declined" button, I want to update clientResponse to respectively "approved" or "declined". To do this I added these custom code in WordPress theme editor: function custom_thank_you_content() { if (is_page('thank-you')) { // Check if it's the 'Thank You' page if (isset($_GET['response']) && isset($_GET['email'])) { $response = sanitize_text_field($_GET['response']); $email = sanitize_email($_GET['email']); if ($response == 'approved') { echo '<h2>Thank You!</h2>'; echo '<p>We are thrilled to know you are interested. We will get in touch with you shortly.</p>'; } elseif ($response == 'declined') { echo '<h2>Thank You for Your Response!</h2>'; echo '<p>We appreciate your feedback. If you change your mind, feel free to contact us anytime.</p>'; } } else { echo '<h2>Thank You!</h2>'; echo '<p>We appreciate your response.</p>'; } exit; // End script execution to prevent the default page content from loading } } add_action('wp', 'custom_thank_you_content'); function update_customer_response($response, $email) { global $wpdb; // This brings the global $wpdb object into the local function scope $table_name = $wpdb->prefix . 'db7_forms'; // Accessing the table with the WordPress database prefix // Update the customerResponse field where the email matches $wpdb->update( $table_name, array('clientResponse' => $response), array('form_value' => $email) ); } But the resesponse is not updating. What can be the reason and how can I achieve it?

Comment (0)

You’ll be in good company