• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

BUG Compatibility with Older Insert PHP

jmcadmin

New member
Messages
8
Likes
0
Points
1
#1
Thank you for providing the 2.2.7's ability to continue with [insert_php], as it would have been a nightmare to create all the pages again as snippets. However we noted that the code included in [insert_php] is run multiple times, resulting in multiple mysql insertions, file uploads and similar multiplication errors. When the same code is executed via a snippet, this problem does not arise.

Is there anything we can do to prevent this, at least as as a temporary measure, until this is fixed. I tried searching for any similar threads but none was found. This error was not there with the previous versions of the plugin earlier. However, now the problem does not go away even if the older v1.3 is used.

Please help. I hope I am clear enough.

TIA
 
Last edited:

Temyk

Support team
Staff member
Messages
213
Likes
13
Points
18
#2
Hello!

The [insert_php] shortcode is executed only once. If you experience multiple execution, check where else this code is used.

Can you send me a code that runs multiple times? and a screenshot of the editor of the post where the shortcode is inserted
 

jmcadmin

New member
Messages
8
Likes
0
Points
1
#3
Code:
 [insert_php]
if (current_user_can ('a_super')) { }
else {
    if (!current_user_can ('a_backoffice')) {
        header('Location: /');
        exit();
    }
    else {
        if (!current_user_can ('a_apps_com')) {
            setcookie("no_apps", 1, time()+3600, "/");
            header('Location: /bo');
            exit();
        }
    }
}

echo '<style>
.vc_col-sm-2 {
    font-weight: bold;
    text-align: left;
}
.nobold {
    font-weight: normal;
}
</style>';

$date = new DateTime();       
$date->setTimeZone(new DateTimeZone("Asia/Colombo"));       
$nowdt = $date->format("Y-m-d h:i a");
include 'wp-content/php/bddata.php';

$addrem = mysqli_query($conn,"INSERT INTO a_apps_remarks (app_id, ref, remark, uid, proc_date) values ('8108472', '8108472', 'test', '$wpuid', '$nowdt')");

[/insert_php]
11.PNG 22.PNG


Hope this is helpful for your investigation. The actual code is more complex than this. I took a simple example of the code I have, which still results in duplicate entries. The same code executes correctly in older versions 4.9.

Similarly, when I try to upload a file, I get an error saying that the file cannot be found, but the file is uploaded to the correct folder with correct file name generated by the script. It is like the code is always executed 3 times without me knowing.

However, this issue is not there when I use a snippet to run the script. But since there is a heap of [insert_php] codes are there, checnging them to snippets is not practical. Please help.
 

Temyk

Support team
Staff member
Messages
213
Likes
13
Points
18
#4
This code runs 3 times if you open the page?
 

Temyk

Support team
Staff member
Messages
213
Likes
13
Points
18
#6
Try adding screen output to your code:
echo "test";
Three times too?
 

jmcadmin

New member
Messages
8
Likes
0
Points
1
#7
Nope. all echo outputs are only one time.
That is why i was thinking that the script is running three times without me knowing. This is further evident with the file uploads, where I get an error saying no uploaded file is found. However, the correct file is uploaded to the correct folder location with the correct filename, all of which are decided by the php script.

Furthermore the print_r($_POST) and print_r($_FILES) output the correct data arrays as expected.
 

Temyk

Support team
Staff member
Messages
213
Likes
13
Points
18
#8
Everything you've described means that the problem is in your code. I can't help you without seeing the whole code and knowing how it works. Try to display the path to the file you are accessing and verify it.
 

Temyk

Support team
Staff member
Messages
213
Likes
13
Points
18
#10
Similarly, when I try to upload a file, I get an error saying that the file cannot be found, but the file is uploaded to the correct folder with correct file name generated by the script. It is like the code is always executed 3 times without me knowing.
There's nothing in your code about downloading a file. But you write about it.
 

jmcadmin

New member
Messages
8
Likes
0
Points
1
#11
There's nothing in your code about downloading a file. But you write about it.
We'll forget about the file upload for now. I think both issues are caused by one problem. So would you PLEASE help me to fix this? Entire organization is broken now.

I tried disabling all other plugins, but the insertion has occured three times without any change.
 

Temyk

Support team
Staff member
Messages
213
Likes
13
Points
18
#12
It's not about other plugins or Woody plugin.
I think it's your code that's the problem.

If you add output to this code, but it is displayed only once, then the problem is not in this code.
Try creating a new page and adding only the code to write to the database
 

Temyk

Support team
Staff member
Messages
213
Likes
13
Points
18
#14
So you have this code somewhere else.
Try changing the data in the query in the last test code. All three records will be with new data?
 

Temyk

Support team
Staff member
Messages
213
Likes
13
Points
18
#16
You can't track where the code was executed. Your code is called somewhere else, you need to find exactly where. Can be in another code connects the text from your page.