I was making this small feature in php where I want a script to collect links. What I want to do is have a text input box and a submit button. When you hit submin, the link gets added to a database and all the links in the database gets loaded on the same page as the form.
I’m using the plugin Exec-PHP to run a php file as an include on a page. When I run the included file as standalone, without it being integrated in a WordPress page, the script runs fine and does exactly what I want it to do. All that is performed is a simple SELECT statement to extract all the links from the database and show them. When the user press submit, the script checks that the text in the input box is an URL, and adds it to the database with an INSERT statement.
Is there a reason for this? I was thinking anyway to write this as a plugin to WordPress instead as I’m guessing there are various hooks in WordPress that makes it run twice. We’ll see if that solves the problem.
I thought maybe using WordPress‘s builtin database functions would help me solve the problem, but still the INSERT queries keep being run twice. I came up with a dirty hack, checking if the link was already in the database before I inserted it, wich I was going to implement either way so there is no double posted links. But that deprived me of the ability to give the user feedback on the link being added, or the link existing already in the database. So, I have to come up with another solution to this problem to make it work correctly like I want it to.