Duplicate data submission

I have a form that submits data twice when it should be only once. I have tried using the solutions I found online but nothing worked. ANy ideas on how I can achieve this?

My code looks like below.

 if (isset($_POST[$blockUserButton])){
        global $wpdb;

$table_name= my_tale;

$wpdb->insert($table_name, array('userReporter' => $_POST['userReporter'], 'reportedUser' => $_POST['reportedUser'], 'reportReason' => $_POST['reportReason'], 'reportReasonSelect' => $_POST['reportReasonSelect'] ) );



1 Like

Is this code part of a function?

No, not part of a function.

Above the insert line add:

echo 'I have been run';

Does that get echoed twice?

Only a wild guess.

By any chance is the form being submitted by AJAX and you forgot a preventDefault ?

Le me do that

Striclty php

Just once!

I notice the example code in the first post has an extra closing curly brace.

That may be what is responsible for the problem, but I suspect it has more to do with where you are calling in that file. (in the “loop” somewhere?)

But as you see “I have been run” only once I’m not so sure of that either.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.