Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have enabled custom php in my pages through the use of the exec-php plugin so I can run more complex pages than the standard WordPress page. I have had no problems with this plugin so far.

I have recently moved a page I was using independently from WordPress to inside the WordPress system. Now instead of running a INSERT mysql query once like it should, it runs it 4 times leaving me with 3 redundant rows in my database. As far as I can tell there is no help on this issue, has anybody encountered this problem or know of a way to circumvent this?

As it may impact the answer I am using mysql_query() in favour of $wpdb->query().

EDIT:
I have since rewrote the page to use the most appropriate $wbdb function (my code can be found here).

In addition I found that when I use $wpdb->flush(); it inserts 1 row only however it seems to break the loop as it doesn't load the template.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Using a plugin to run PHP code inside your content is not the sanest thing to do, especially when said code is not idempotent.

Basically, you cannot guarantee that your code will only run once per page load, since several different things in the system may be processing your content, and thus executing your code, multiple times.

Instead of using Exec-PHP to store the code in the post content, create a Page Template which contains your code, then attach it to the Page in question. Also, rewrite your code so that calling it multiple times doesn't produce incorrect results (people often double-click buttons and such on the web).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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