Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 16 of 16
  1. #16
    New to the CF scene
    Join Date
    Nov 2013
    Thanked 1 Time in 1 Post


    Apologies for the response to an old post, but after literally days of searching, this thread helped me find the solution to a duplicate insert problem (PHP + MySQL).

    As the contributors above noted, the issue turned out not to be in the PHP code, but instead the Javascript form validation routine.

    The one thing I would add to atapoverseer's comment is to check the actual input type of your submit button.

    If your html form button calls the javascript validation function via "OnClick", make sure the button type is NOT "submit", but rather "button".

    What DIDN'T work:
    <input type="submit" value="Submit" OnClick="validate_form();">
    What DID work:
    <input type="button" value="Submit" OnClick="validate_form();">
    Here's why -- the "submit" button type posts the form regardless of the function that is being called for validation, thus creating first a form submission (without validation check), followed by a validation check within the javascript function, which if true posts the form again to the php code that fires off the insert request to your MySQL database.

    In contrast, the "button" type doesn't do anything on click unless instructed to do so by the javascript routine connected to it. Thus, the form data is only posted once if it passes the validation routine.

    I hope this saves someone else some time

  2. Users who have thanked 7N89 for this post:

    phantom007 (11-05-2013)

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts