If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Query inserting twice.

I've been trying to figure out why the queries on liked_button.php are entering twice for about 24 hrs now with no luck.

I have a liked button that users can click, when that button is clicked, info goes to liked_button.php, that info is subsequently transferred to the `likes` and `notifications` table. But for some reason, the query runs twice.

Would cover all the bases -- not sure how you integrate that into the bloated wreck that is jQuery. I think it has the prevent() method...

It might also help if you had a COMPLETE form with at the very least a fieldset, since INPUT as direct children of FORM is invalid markup, not sure why you're putting classes on hidden inputs, you could probably use proper double quotes in the markup if you stopped using slow double quotes in your PHP...

Then there's the SQL side of things, where you're not sanitizing the $_GET data just begging to be hacked, and basically you're using mysqli like it was the old mysql_ functions, instead of using it properly with prepared queries.

Also not sure why you're playing games with date and time when mySQL has a perfectly good DATETIME field and NOW() operation.

Though I'm guessing wildly and the above code is untested. I generally don't use jQuery (though I took the time to learn it BEFORE I started badmouting it) or mysqli (I'm a PDO guy)... but still that should be enough for you to get how it should be done.

Because you aren't preventing the submit event... I don't think... Really that's a mess because you have a onsubmit AND a onclick -- on a form that actually again shouldn't be trapping the mouse-only event on the submit for the form.

The validate AND the leaveYourComment should BOTH be run on the FORM:nsubmit

Though again, as with the other example I'd be hooking from the scripting instead of using the onevent methods... and as before there's no reason to put a class on hidden inputs; and something I didn't mention was that if that data is all static, why are you wasting time sending it client-side in the first place instead of storing it in the session?

Again, attach to the submit, use the validateForm to determine if the ajax should be run. All one operation, with none of those onevent attributes in the markup.

Pretty much these days if you are saying "onmouseover" or "onsubmit" or "onclick" in the HTML, you're doing it all wrong. Likewise trapping clicks on the submit button doesn't help for keyboard users -- when you want to trap the form being sent for ajax or for validation, you trap the form submit, not clicks on a button/input.